Artisan Generator Commands
Edit onTip:
You can use --help
with any of the following commands to find
its arguments and options.
Note: All of the following commands use "Blog" as an example module name, and example class/file names.
Note:
Many of the generator commands also support nested folder structures. For example, if you wanted to generate
a model inside a directory called "PostModel", you could call php artisan module:make-model PostModel/Post Blog
.
This will generate the model with the correct namespace and place it inside of Modules/Blog/Models/PostModel/Post.php
.
module:make
Generate a new module
php artisan module:make Blog
To generate multiple modules at once, you can pass them in as additional arguments.
php artisan module:make Blog User Auth
module:make-command
Generate a console command for the specified module.
php artisan module:make-command CreatePostCommand Blog
Options:
-
--signature=command-signature
: This will be the name of the terminal command. -
--argument=argument
: This will add an argument to the command signature. This can be called multiple times for multiple arguments. -
--option=option
: This will add an option to the command signature. This can be called multiple times for multiple options. -
--description=description
: This will set the command description.
module:make-controller
Generate a new controller for the specified module.
php artisan module:make-controller PostsController Blog
Options:
-
--plain
,-p
: This will generate a plain controller. -
--base_class=CustomBaseClass
: Override the base class the generated controller will extend.
module:make-event
Generate an event for the specified module.
php artisan module:make-event BlogPostWasUpdated Blog
Options:
-
--plain
,-p
: Create a plain event class.
module:make-factory
Generate a database factory for the specified module.
php artisan module:make-factory PostFactory Blog
Options:
-
--model=ModelName
: The name of the model the factory is for.
module:make-job
Generate a job for the specified module.
php artisan module:make-job DeleteExpiredPosts Blog
Options:
-
--sync
,-s
: Indicates the job should by synchronus.
module:make-listener
Generate an event listener for the specified module. Optionally you can specify which event class it should listen to.
php artisan module:make-listener NotifyUsersOfANewPost Blog
Options:
-
--event
,-e
: The event class being listened for. -
--queued
: Indicates the event listener should be queued.
module:make-mail
Generate a mailable for the specified module.
php artisan module:make-mail SendWeeklyPostsEmail Blog
Options:
-
--base_class=CustomBaseClass
: Override the base class the generated mailable will extend.
module:make-middleware
Generate a middleware class for the specified module.
php artisan module:make-middleware CanReadPostsMiddleware Blog
module:make-migration
Generate a database migration for the specified module.
php artisan module:make-mail create_posts_table Blog
Options:
-
--fields=username:string,password:string
: The fields to migrate.
module:make-model
Generate an Eloquent model for the specified module.
php artisan module:make-model Post Blog
Options:
-
--base_class=CustomBaseClass
: Override the base class the generated mailable will extend. -
--fillable=field1,field2
: Set the fillable fields on the generated model -
--migration
,-m
: Create a migration file for the generated model -
--table=table_name
: Set the name of the generated model's database table.
module:make-policy
Generate a policy class for the specified module.
php artisan module:make-policy PostPolicy Blog
module:make-provider
Generate a service provider for the specified module.
php artisan module:make-provider BlogServiceProvider Blog
Options:
-
--master
,-m
: Indicates the provider is a master service provider.
module:make-repository
Generate a new repository for the specified module.
Note: This is a very opinionated generator. The generator and the options it accepts are based primarily off of the repositories I use in my own projects.
php artisan module:make-repository PostRepository Blog --model Modules/Blog/Models/Post
Options:
-
--base_class=CustomBaseClass
: Override the default repository class. -
--model=Path/To/Model
: The model the repository is for. Give the full path (namespace) to the model. -
--not_found_message="Your not found message"
: The 404 message to output for exceptions that get thrown from the base repository. -
--plain
,-p
: Generate a plain repository.
module:make-request
Generate a new form request class for the specified module.
php artisan module:make-request CreatePostRequest Blog
Options:
-
--base_class=CustomBaseClass
: Override the base class the generated request will extend.
module:make-resource
Generate a resource class for the specified module.
php artisan module:make-resource PostResource Blog
Options:
-
--collection
,-c
: Create a resource collection class.
module:make-rule
Generate a new validation rule class for the specified module.
php artisan module:make-rule CustomValidationRule Blog
module:make-seed
Generate a database seeder for the specified module.
php artisan module:make-seed seed_blog_posts Blog
Options:
-
--master
,-m
: Indicates the seeder is a master database seeder
module:make-test
Generate a test for the specified module.
php artisan module:make-test PostTest Blog
module:route-provider
Generate a new route service provider for the specified module.
php artisan module:route-provider Blog
- Compiling Assets
- Artisan Utility Commands