Source + website, updated for Laravel 10
- make:cast Create a new custom Eloquent cast class
- make:channel Create a new channel class
- make:command Create a new Artisan command
- make:component Create a new view component class
- make:controller Create a new controller class
- make:event Create a new event class
- make:exception Create a new custom exception class
- make:factory Create a new model factory
- make:job Create a new job class
- make:listener Create a new event listener class
- make:mail Create a new email class
- make:middleware Create a new middleware class
- make:migration Create a new migration file
- make:model Create a new Eloquent model class
- make:notification Create a new notification class
- make:observer Create a new observer class
- make:policy Create a new policy class
- make:provider Create a new service provider class
- make:request Create a new form request class
- make:resource Create a new resource
- make:rule Create a new validation rule
- make:scope Create a new scope class
- make:seeder Create a new seeder class
- make:test Create a new test class
Note : make:auth
has been removed in Laravel 6.
Note : most of commands have the [-f|--force]
option to create the class even if file already exists.
Note : most of commands have the [--test] [--pest]
options to generate an accompanying PHPUnit / Pest test for the class.
This command creates a new custom Eloquent cast class in app/Casts
. Doc
php artisan make:cast [--inbound] <name>
--inbound
Generate an inbound cast class. Doc
php artisan make:cast Json
php artisan make:cast Hash --inbound
Create a new channel class for broadcasting in app/Broadcasting
. Doc
php artisan make:channel <name>
php artisan make:channel OrderChannel
This command creates a new Artisan command in app/Console/Commands
. Doc
php artisan make:command [--command [COMMAND]] <name>
--command
The terminal command that will be used to invoke the class. Officially undocumented parameter.
php artisan make:command SendEmails
This command creates a new view component class in app/View/Components
. Doc
php artisan make:component [--inline] [--view] <name>
Note : if the
--inline
option is not set, a file will be created inresources/views/components
.
--inline
Create a component that renders an inline view. Doc--view
Create an anonymous component with only a view.
php artisan make:component Alert
php artisan make:component Forms/Input
php artisan make:component forms.input --view
php artisan make:component Alert --inline
This command creates a new controller class in app/Http/Controllers
. Doc
php artisan make:controller [--api] [-i|--invokable] [-m|--model [MODEL]] [-p|--parent [PARENT]] [-r|--resource] [-R|--requests] [-s|--singleton] [--creatable] [--type [TYPE]] <name>
-r, --resource
The controller will contain a method for each of the available resource operations – index(), create(), store(), show(), edit(), update(), destroy(). Doc--api
Similar to--resource
above, but exclude the create and edit methods (because forms are not needed for API). Doc-i, --invokable
Generates controller with one__invoke()
method. Doc-m, --model
If you are using route model binding and would like the resource controller’s methods to type-hint a model instance. Creates file inapp/Models
. Doc-p, --parent
Generate a nested resource controller class. Note : failed to generate a Controller properly. Officially undocumented parameter.-R, --requests
Generate FormRequest classes for store and update. To use with the--model
option. Creates files inapp/Http/Requests
. Doc-s, --singleton
Generate a singleton resource controller class. Addsabort(404)
for the methods create, store and destroy. Officially undocumented parameter.--creatable
Indicate that a singleton resource should be creatable. Officially undocumented parameter.--type
Manually specify the controller stub file to use. Officially undocumented parameter.
php artisan make:controller UserController
php artisan make:controller ProvisionServer --invokable
php artisan make:controller PhotoController --resource
php artisan make:controller PhotoController --model=Photo --resource
php artisan make:controller PhotoController --model=Photo --resource --requests
php artisan make:controller PhotoController --api
This command creates a new event class in app/Events
. Doc
php artisan make:event <name>
php artisan make:event PodcastProcessed
This command creates a new custom exception class in app/Exceptions
. Officially undocumented command.
php artisan make:exception <name>
--render
Create the exception with an empty render method.--report
Create the exception with an empty report method.
This command creates a new model factory in database/factories
. Doc
php artisan make:factory [-m|--model [MODEL]] <name>
-m, --model
The name of the model. Officially undocumented parameter.
php artisan make:factory PostFactory
This command creates a new job class in app/Jobs
. Doc
php artisan make:job [--sync] <name>
--sync
Indicates that job should be synchronous. Officially undocumented parameter.
php artisan make:job ProcessPodcast
This command creates a new event listener class in app/Listeners
. Doc
php artisan make:listener [-e|--event [EVENT]] [--queued] <name>
-e, --event
The event class being listened for.--queued
Indicates the event listener should be queued. Officially undocumented parameter.
php artisan make:listener SendPodcastNotification --event=PodcastProcessed
This command creates a new email class in app/Mail
. Doc
php artisan make:mail [-m|--markdown [MARKDOWN]] <name>
-m, --markdown
Create a new Markdown template for the mailable inresouces/views
. Doc
php artisan make:mail OrderShipped
php artisan make:mail OrderShipped --markdown=mail.orders.shipped
This command creates a new middleware class in app/Http/Middleware
. Doc
php artisan make:middleware <name>
php artisan make:middleware EnsureTokenIsValid
This command creates a new migration file in database/migrations
. Doc
Note : file will be generated with timestamp, like this :
[Y]_[m]_[d]_[His]_<name>.php
Runphp artisan migrate
to run migration.
Runphp artisan migrate:refresh --seed
to reset database with seed values.
php artisan make:migration [--create [CREATE]] [--table [TABLE]] [--path [PATH]] [--realpath] [--fullpath] <name>
--create
The table to be created. Officially undocumented parameter.--table
The table to migrate. Officially undocumented parameter.--path
The location where the migration file should be created.--realpath
Indicate any provided migration file paths are pre-resolved absolute path. Officially undocumented parameter.--fullpath
Output the full path of the migration. Officially undocumented parameter.
php artisan make:migration create_flights_table
This command creates a new Eloquent model class in app/Models
. Doc
php artisan make:model [-a|--all] [-c|--controller] [-f|--factory] [-m|--migration] [--morph-pivot] [--policy] [-s|--seed] [-p|--pivot] [-r|--resource] [--api] [-R|--requests] <name>
Short syntax :
php artisan make:model -mcr <name>
-a, --all
Generate a migration, seeder, factory, policy, resource controller, and form request classes for the model.-c, --controller
Create a new controller for the model.-f, --factory
Create a new factory for the model.-m, --migration
Create a new migration file for the model.--morph-pivot
Indicates if the generated model should be a custom polymorphic intermediate table model. Officially undocumented parameter.--policy
Create a new policy for the model.-s, --seed
Create a new seeder for the model.-p, --pivot
Indicates if the generated model should be a custom intermediate table model.-r, --resource
Indicates if the generated controller should be a resource controller.--api
Indicates if the generated controller should be an API resource controller.-R, --requests
Create new form request classes and use them in the resource controller.
php artisan make:model Flight
php artisan make:model Flight --migration
# Generate a model and a FlightFactory class...
php artisan make:model Flight --factory
php artisan make:model Flight -f
# Generate a model and a FlightSeeder class...
php artisan make:model Flight --seed
php artisan make:model Flight -s
# Generate a model and a FlightController class...
php artisan make:model Flight --controller
php artisan make:model Flight -c
# Generate a model, FlightController resource class, and form request classes...
php artisan make:model Flight --controller --resource --requests
php artisan make:model Flight -crR
# Generate a model and a FlightPolicy class...
php artisan make:model Flight --policy
# Generate a model and a migration, factory, seeder, and controller...
php artisan make:model Flight -mfsc
# Shortcut to generate a model, migration, factory, seeder, policy, controller, and form requests...
php artisan make:model Flight --all
# Generate a pivot model...
php artisan make:model Member --pivot
php artisan make:model Member -p
This command creates a new notification class in app/Notifications
. Doc
php artisan make:notification [-m|--markdown [MARKDOWN]] <name>
-m, --markdown
Create a new Markdown template for the notification inresouces/views
. Doc
php artisan make:notification InvoicePaid
php artisan make:notification InvoicePaid --markdown=mail.invoice.paid
This command creates a new observer class in app/Observers
. Doc
php artisan make:observer [-m|--model [MODEL]] <name>
-m, --model
The model that the observer applies to.
php artisan make:observer UserObserver --model=User
This command creates a new policy class in app/Policies
. Doc
php artisan make:policy [-m|--model [MODEL]] [-g|--guard [GUARD]] <name>
-m, --model
The model that the policy applies to.-g, --guard
The guard that the policy relies on. Officially undocumented parameter.
php artisan make:policy PostPolicy
php artisan make:policy PostPolicy --model=Post
This command creates a new service provider class in app/Providers
. Doc
php artisan make:provider <name>
php artisan make:provider RiakServiceProvider
This command creates a new form request class in app/Http/Requests
. Doc
php artisan make:request <name>
php artisan make:request StorePostRequest
This command creates a new resource in app/Http/Resources
. Doc
php artisan make:resource [-c|--collection] <name>
-c, --collection
Create a ResourceCollection instead of individual Resource class. Doc
php artisan make:resource UserResource
php artisan make:resource User --collection
php artisan make:resource UserCollection
This command creates a new validation rule in app/Rules
. Doc
php artisan make:rule [-i|--implicit] <name>
-i, --implicit
Generate an implicit rule. Doc
php artisan make:rule Uppercase
php artisan make:rule Uppercase --implicit
This command creates a new scope class in app/Models/Scopes
. Doc
php artisan make:scope <name>
php artisan make:scope AncientScope
This command creates a new database seeder class in database/seeders
. Doc
php artisan make:seeder <name>
php artisan make:seeder UserSeeder
This command creates a new test class in test/Feature
. Doc
php artisan make:test [-u|--unit] [-p|--pest] <name>
-u, --unit
Create a unit test intest/Unit
.-p, --pest
Create a Pest test.
php artisan make:test UserTest --unit --pest
Good