1. Home
  2. Docs
  3. laravel
  4. “php artisan make:&...
  5. artisan make:controller

artisan make:controller


  • Controllers are used when it’s too complex to just specify a (static) view in the routes list.
  • Controllers typically return a view (in the most common case of a web view, thus a rendered HTML page).


>php artisan make:controller FooController
   Create a new controller class

   make:controller [options] [--] <name>

   name                   The name of the class

       --api              Exclude the create and edit methods from the controller.
       --force            Create the class even if the controller already exists
   -i, --invokable        Generate a single method, invokable controller class.
   -m, --model[=MODEL]    Generate a resource controller for the given model.
   -p, --parent[=PARENT]  Generate a nested resource controller class.
   -r, --resource         Generate a resource controller class.
   -h, --help             Display this help message
   -q, --quiet            Do not output any message
   -V, --version          Display this application version
       --ansi             Force ANSI output
       --no-ansi          Disable ANSI output
   -n, --no-interaction   Do not ask any interactive question
       --env[=ENV]        The environment the command should run under
   -v|vv|vvv, --verbose   Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug 



The controller will contain a method for each of the available resource operations – index(), create(), store(), show(), edit(), update(), destroy().


Similar to –resource above, but generate only 5 methods: index(), store(), show(), update(), destroy(). Because create/edit forms are not needed for API.


Generates controller with one __invoke() method.


If you are using route model binding and would like the resource controller’s methods to type-hint a model instance.


Output will be in app/Http/Controllers:

Reference: https://laravel.com/docs/6.x/controllers

Tags , ,