Artisan is a command-line interface included with Laravel. Laravel uses many components from Symfony and Artisan is also one of them ( powerful Symfony Console component ). Laravel is built for rapid application development and Artisan provides many helpful commands to make it possible like we normally using commands like :
php artisan make:model Country
Above commands will generate Country model for us. We also posted another article before for generating model, migration and resource controller in one line of command . This is just some of the commands we use on a daily basis.
Today we are going to deep dive into Laravel Artisan. Now, let’s get started.
First let’s see the list of commands we can use.
php artisan list
Above line of commands will list out all the commands we can use with artisan . We can find sections like make, migrate, notifications, app, auth, cache,config. Try it out , you may not have used all of those awesome commands yet . 🙂
Now, mastering laravel artisan commands is easy once we list them out using above command. How ? we can use help flag on every commands to go into detail. Let’s see some demonstration.
You can see in our make:model command, we used a flag -h . Now you can try it out all of those options like :
php artisan make:model User -a
// Generate a migration, factory, and resource controller for the model
php artisan make:model User -m
// Create a new migration file for the model.
We can also use –help or -h to see options and their description of what they will do. Easy right ! 🙂 Now we can use help options whenever we want more when we create something like model, controller or whatever .
You can go through other commands like php artisan migrate -h, this will provides other options you can try out like :
–database (The database connection to use)
–step (Indicates if the seed task should be re-run.)
–version (Display this application version)
–seed (Indicates if the seed task should be re-run.)
You see as we go deeper we can find many options . These options will help you speed up your application development faster. There are many packages available too for other generator for traits, repository and many other.
It might be hard to remember all the options and commands but as you keep on testing and using in time you will use all of those commands . We hope we were able to help you understand the artisan . If you have any queries or suggestions for us, feel free to contact us here.
Happy coding 🙂