Welcome to CodeCrew Infotech
In this blog, I will explain the Artisan command. Artisan is the name of the command-line interface included with Laravel. It provides many helpful commands for your use while developing Projects
So, you can read and learn the command in laravel project to very useful
So, lets start with the artisan command to learn
This command creates a new controller file in the app/Http/Controllers folder.
Example usage:
php artisan make:controller UserController
Parameters:
--resource
The controller will contain a method for each of the available resource operations – index(), create(), store(), show(), edit(), update(), destroy().
--api
Similar to –resource above, but generate only 5 methods: index(), store(), show(), update(), destroy(). Because create/edit forms are not needed for API.
--invokable
Generates controller with one __invoke() method. Read more about invokable controllers here.
--model=Photo
If you use route model binding and want the resource controller’s methods to type-hint a model instance.
--parent=Photo
Officially undocumented parameter, in the code it says “Generate a nested resource controller class” but for me, it failed to generate a Controller properly. So probably a work in progress.
Create a new Eloquent model class.
Example usage:
php artisan make:model Photo
Parameters:
--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 if the generated controller should be a resource controller.
Yes, you’ve got it 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 to make:model.
--factory
or
-f
Create a new factory for the model.
--all
or
-a
Generate the above: a migration, factory, and resource controller for the model.
And even that’s not all.
--force
Create the class even if the model already exists.
--pivot
Indicates if the generated model should be a custom intermediate table model.
Create a new migration file.
Example usage:
php artisan make:migration create_projects_table
Parameters:
--create=Table
The table to be created.
--table=Table
The table to migrate.
--path=Path
The location where the migration file should be created.
--realpath
Indicate any provided migration file paths are a pre-resolved absolute paths.
--fullpath
Output the full path of the migration.
Create a new database seeder class.
Example usage:
php artisan make:seeder BooksTableSeeder
Parameters: none.
Create a new form request class in the app/Http/Requests folder.
Example usage:
php artisan make:request StoreBlogPost
Parameters: none.
Create a new middleware class.
Example usage:
php artisan make:middleware CheckAge
Parameters: none.
Create a new policy class.
Example usage:
php artisan make:policy PostPolicy
Parameters:
--model=Photo
The model that the policy applies to.
Create a new Artisan command.
Example usage:
php artisan make:command SendEmails
Parameters:
--command=Command
The terminal command that should be assigned.
Create a new event class.
Example usage:
php artisan make:event OrderShipped
Parameters: none.
Create a new job class.
Example usage:
php artisan make:job SendReminderEmail
Parameters:
--sync
Indicates that job should be synchronous.
Create a new event listener class.
Example usage:
php artisan make:listener SendShipmentNotification
Parameters:
--event=Event
The event class is being listened to.
--queued
Indicates the event listener should be queued.
Create a new email class.
Example usage:
php artisan make:mail OrderShipped
Parameters:
--markdown
Create a new Markdown template for the mailable.
--force
Create the class even if the mailable already exists.
Create a new notification class.
Example usage:
php artisan make:notification InvoicePaid
Parameters:
--markdown
Create a new Markdown template for the notification.
--force
Create the class even if the notification already exists.
Create a new service provider class.
Example usage:
php artisan make:provider DuskServiceProvider
Parameters: none.
Create a new test class.
Example usage:
php artisan make:test UserTest
Parameters:
--unit
Create a unit (or, otherwise, feature) test.
Create a new channel class for broadcasting.
Example usage:
php artisan make:channel OrderChannel
Parameters: none.
Create a new custom exception class.
Example usage:
php artisan make:exception UserNotFoundException
Parameters:
--render
Create the exception with an empty render method.
--report
Create the exception with an empty report method.
Create a new model factory.
Example usage:
php artisan make:factory PostFactory --model=Post
Parameters:
--model=Post
The name of the model.
Create a new observer class.
Example usage:
php artisan make:observer PostObserver --model=Post
Parameters:
--model=Post
The model that the observer applies to.
Create a new validation rule.
Example usage:
php artisan make:rule Uppercase
Parameters: none.
Create a new API resource.
Example usage:
php artisan make:resource PostResource
Parameters:
--collection=Post
Create a ResourceCollection instead of an individual Resource class.