Laravel has an impressive set of artisan commands, perhaps the most frequently used being create:xxx – liked make:model or create: migration etc. But did you know all 21? And, what’s more, do you know the parameters that can help make the code faster?
See: this article was originally written in August 2017, with 16 commands, now updated in October 2019 for the latest version of Laravel 6, with 21 commands.
First, there are orders list of php builders which gives us all the commands, like this:
make:channel Create a new channel class make:command Create a new Artisan command 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:seeder Create a new seeder class make:test Create a new test class
See: if you are surprised don’t see it create: auth command, it was removed in Laravel 6 and separated into its own UI package.
The above list does not give us any information about the parameters or options for this command. So I want to review each of them here, starting with the most frequently used.
For this reason, we will dive into the actual code of the framework, within it /vendor/laravel/framework/src/Illuminate folder, and will check what undocumented options and features we have for each command.
1. create: controller
This command creates a new controller file app/Http/Controllers folder.
Example of use:
php artisan make:controller UserController
Parameter:
--resource
The controller will contain methods for each available resource operation – index(), create(), save(), display(), edit(), update(), destroy().
--api
Similar to -source above, but only produces 5 methods: index(), store(), show(), update(), destroy(). Because creating/editing forms is not required for the API.
--invokable
Generates a controller with one __request() method. Read more about callable controllers here.
--model=Photo
If you use route model binding and want a resource controller method type model instance hint.
--parent=Photo
Official parameters are undocumented, in written code “Create a nested resource controller class” but for me it fails to generate the Controller correctly. So maybe work is in progress.
2. make: model
Create a new Eloquent model class.
Example of use:
php artisan make:model Photo
Parameter:
--migration
or
-m
Create a new migration file for the model.
--controller
or
-c
Create a new controller for the model.
--resource
or
-r
Indicates whether the resulting controller should be a resource controller.
Yes, you are right, you can do it like this:
php artisan make:model Project --migration --controller --resource
Or even shorter:
php artisan make:model Project -mcr
But that’s not all make:model.
--factory
or
-f
Create a new factory for the model.
--all
or
-a
Generate all of the above: migrations, factories, and resource controllers for models.
And that’s not even all.
--force
Create a class even if the model already exists.
--pivot
Indicates whether the resulting model should be a custom intermediate table model.
3. create: migration
Create a new migration file.
Example of use:
php artisan make:migration create_projects_table
Parameter:
--create=Table
The table to be created.
--table=Table
The table to be migrated.
--path=Path
The location where the migration file should be created.
--realpath
Indicate that any migration file paths provided are pre-resolved absolute paths.
--fullpath
Output the full migration path.
4. make: seeder
Create a new database seeder class.
Example of use:
php artisan make:seeder BooksTableSeeder
Parameter: There isn’t any.
5. make: request
Create a new form request class in app/Http/Requests folder.
Example of use:
php artisan make:request StoreBlogPost
Parameter: There isn’t any.
6. making: intermediate equipment
Create a new middleware class.
Example of use:
php artisan make:middleware CheckAge
Parameter: There isn’t any.
7. create: policy
Create a new policy class.
Example of use:
php artisan make:policy PostPolicy
Parameter:
--model=Photo
The model in which the policy is implemented.
8. create: command
Create a new Artisan command.
Example of use:
php artisan make:command SendEmails
Parameter:
--command=Command
Terminal commands to be assigned.
9. create: event
Create a new event class.
Example of use:
php artisan make:event OrderShipped
Parameter: There isn’t any.
10. make: work
Create a new job class.
Example of use:
php artisan make:job SendReminderEmail
Parameter:
--sync
Indicates that the work should be synchronous.
11. make: listener
Create a new event listener class.
Example of use:
php artisan make:listener SendShipmentNotification
Parameter:
--event=Event
The class of the event being watched.
--queued
Indicates event listeners should queue.
12. make: letter
Create a new email class.
Example of use:
php artisan make:mail OrderShipped
Parameter:
--markdown
Create a new markdown template for mailings.
--force
Create a class even if mailable already exists.
13. create: notification
Create a new notification class.
Example of use:
php artisan make:notification InvoicePaid
Parameter:
--markdown
Create a new Markdown template for notifications.
--force
Create a class even if the notification already exists.
14. make: provider
Create a new service provider class.
Example of use:
php artisan make:provider DuskServiceProvider
Parameter: There isn’t any.
15. make: test
Create a new test class.
Example of use:
php artisan make:test UserTest
Parameter:
--unit
Create unit (or, feature) tests.
16. create: channel
Create a new channel class for broadcasting.
Example of use:
php artisan make:channel OrderChannel
Parameter: There isn’t any.
17. make: exception
Create a new custom exception class.
Example of use:
php artisan make:exception UserNotFoundException
Parameter:
--render
Create an exception with the empty render method.
--report
Create an exception with the empty report method.
18. make: factory
Create a new model factory.
Example of use:
php artisan make:factory PostFactory --model=Post
Parameter:
--model=Post
The model name.
19. create:observer
Create a new observer class.
Example of use:
php artisan make:observer PostObserver --model=Post
Parameter:
--model=Post
The model applied by the observer.
20. make: rules
Create a new validation rule.
Example of use:
php artisan make:rule Uppercase
Parameter: There isn’t any.
21. create: resources
Create a new API resource.
Example of use:
php artisan make:resource PostResource
Parameter:
--collection=Post
Create a ResourceCollection instead of individual Resource classes.
So, that’s it – 21 commandments covered. Is something missing? Or would you like to see some new parameters for your favorite commands? Share in the comments!
Berita Terkini
Berita Terbaru
Daftar Terbaru
News
Berita Terbaru
Flash News
RuangJP
Pemilu
Berita Terkini
Prediksi Bola
Togel Deposit Pulsa
Technology
Otomotif
Berita Terbaru
Daftar Judi Slot Online Terpercaya
Slot yang lagi gacor
Teknologi
Berita terkini
Berita Pemilu
Berita Teknologi
Hiburan
master Slote
Berita Terkini
Pendidikan
Resep
Jasa Backlink
One Piece Terbaru