Skip to content

Instantly share code, notes, and snippets.

@rseon
Last active April 25, 2024 14:07
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rseon/cbb1277f90c45d6677b15ccf6805595c to your computer and use it in GitHub Desktop.
Save rseon/cbb1277f90c45d6677b15ccf6805595c to your computer and use it in GitHub Desktop.

24 Artisan Make Commands

Source + website, updated for Laravel 10

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.


make:cast

This command creates a new custom Eloquent cast class in app/Casts. Doc

php artisan make:cast [--inbound] <name>

Options

  • --inbound Generate an inbound cast class. Doc

Examples

php artisan make:cast Json
php artisan make:cast Hash --inbound

make:channel

Create a new channel class for broadcasting in app/Broadcasting. Doc

php artisan make:channel <name>

Example

php artisan make:channel OrderChannel

make:command

This command creates a new Artisan command in app/Console/Commands. Doc

php artisan make:command [--command [COMMAND]] <name>

Options

  • --command The terminal command that will be used to invoke the class. Officially undocumented parameter.

Example

php artisan make:command SendEmails

make:component

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 in resources/views/components.

Options

  • --inline Create a component that renders an inline view. Doc
  • --view Create an anonymous component with only a view.

Examples

php artisan make:component Alert
php artisan make:component Forms/Input
php artisan make:component forms.input --view
php artisan make:component Alert --inline

make:controller

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>

Options

  • -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 in app/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 in app/Http/Requests. Doc
  • -s, --singleton Generate a singleton resource controller class. Adds abort(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.

Examples

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

make:event

This command creates a new event class in app/Events. Doc

php artisan make:event <name>

Example

php artisan make:event PodcastProcessed

make:exception

This command creates a new custom exception class in app/Exceptions. Officially undocumented command.

php artisan make:exception <name>

Options

  • --render Create the exception with an empty render method.
  • --report Create the exception with an empty report method.

make:factory

This command creates a new model factory in database/factories. Doc

php artisan make:factory [-m|--model [MODEL]] <name>

Options

  • -m, --model The name of the model. Officially undocumented parameter.

Example

php artisan make:factory PostFactory

make:job

This command creates a new job class in app/Jobs. Doc

php artisan make:job [--sync] <name>

Options

  • --sync Indicates that job should be synchronous. Officially undocumented parameter.

Example

php artisan make:job ProcessPodcast

make:listener

This command creates a new event listener class in app/Listeners. Doc

php artisan make:listener [-e|--event [EVENT]] [--queued] <name> 

Options

  • -e, --event The event class being listened for.
  • --queued Indicates the event listener should be queued. Officially undocumented parameter.

Example

php artisan make:listener SendPodcastNotification --event=PodcastProcessed

make:mail

This command creates a new email class in app/Mail. Doc

php artisan make:mail [-m|--markdown [MARKDOWN]] <name>

Options

  • -m, --markdown Create a new Markdown template for the mailable in resouces/views. Doc

Examples

php artisan make:mail OrderShipped
php artisan make:mail OrderShipped --markdown=mail.orders.shipped

make:middleware

This command creates a new middleware class in app/Http/Middleware. Doc

php artisan make:middleware <name>

Example

php artisan make:middleware EnsureTokenIsValid

make:migration

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
Run php artisan migrate to run migration.
Run php artisan migrate:refresh --seed to reset database with seed values.

php artisan make:migration [--create [CREATE]] [--table [TABLE]] [--path [PATH]] [--realpath] [--fullpath] <name>

Options

  • --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.

Example

php artisan make:migration create_flights_table

make:model

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>

Options

  • -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.

Examples

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

make:notification

This command creates a new notification class in app/Notifications. Doc

php artisan make:notification [-m|--markdown [MARKDOWN]] <name>

Options

  • -m, --markdown Create a new Markdown template for the notification in resouces/views. Doc

Examples

php artisan make:notification InvoicePaid
php artisan make:notification InvoicePaid --markdown=mail.invoice.paid

make:observer

This command creates a new observer class in app/Observers. Doc

php artisan make:observer [-m|--model [MODEL]] <name>

Options

  • -m, --model The model that the observer applies to.

Example

php artisan make:observer UserObserver --model=User

make:policy

This command creates a new policy class in app/Policies. Doc

php artisan make:policy [-m|--model [MODEL]] [-g|--guard [GUARD]] <name>

Options

  • -m, --model The model that the policy applies to.
  • -g, --guard The guard that the policy relies on. Officially undocumented parameter.

Examples

php artisan make:policy PostPolicy
php artisan make:policy PostPolicy --model=Post

make:provider

This command creates a new service provider class in app/Providers. Doc

php artisan make:provider <name>

Example

php artisan make:provider RiakServiceProvider

make:request

This command creates a new form request class in app/Http/Requests. Doc

php artisan make:request <name>

Example

php artisan make:request StorePostRequest

make:resource

This command creates a new resource in app/Http/Resources. Doc

php artisan make:resource [-c|--collection] <name>

Options

  • -c, --collection Create a ResourceCollection instead of individual Resource class. Doc

Examples

php artisan make:resource UserResource
php artisan make:resource User --collection
php artisan make:resource UserCollection

make:rule

This command creates a new validation rule in app/Rules. Doc

php artisan make:rule [-i|--implicit] <name>

Options

  • -i, --implicit Generate an implicit rule. Doc

Examples

php artisan make:rule Uppercase
php artisan make:rule Uppercase --implicit

make:scope

This command creates a new scope class in app/Models/Scopes. Doc

php artisan make:scope <name>

Example

php artisan make:scope AncientScope

make:seeder

This command creates a new database seeder class in database/seeders. Doc

php artisan make:seeder <name>

Example

php artisan make:seeder UserSeeder

make:test

This command creates a new test class in test/Feature. Doc

php artisan make:test [-u|--unit] [-p|--pest] <name>

Options

  • -u, --unit Create a unit test in test/Unit.
  • -p, --pest Create a Pest test.

Example

php artisan make:test UserTest --unit --pest
@Priyanka2966
Copy link

Priyanka2966 commented Jan 8, 2024

Good

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment