Artisan commands are very useful while developing an application in laravel framework.
A command-line interface provided by Laravel framework by default to interact with the application is known as artisan.
Here are some notes and useful artisan commands. The syntax for executing the artisan commands is as follows.
php artisan command [options] [arguments]
Some of useful artisan commands are as follows:
serve: This command runs the application on the PHP development server.
down: This command is used to put the application into maintenance mode.
up: Bring the application out of maintenance mode.
key:generate It is used to set the 32 characters long application key while creating a new project.
cache:clear It removes the application cache.
config:cache It creates a cache of your application configurations for faster loading.
config:clear It removes the configuration cache file.
Make artisan commands
make:auth It creates basic login and registration functionality in your web application.
make:controller It creates a new controller class.
To make a resourceful controller i.e. all the crud functions created automatically we can run the above command using with --resource or --r parameter.
make:controller controllerName --resource or make:controller controllerName --r
make:model It creates a new model class.
We can make controller and model in same commands as
php artisan make:controller controllerName --model=modelName
make:migration It creates a new database migration file.
route:clear Remove the route cache file
route:list List all registered routes
vendor:publish Publish any publishable assets from vendor packages
view:cache Compile all of the application's Blade templates
view:clear Clear all compiled view files
Database migration commands
migrate: This command run the database migrations created by you and the packages you used to download from composer.
migrate:fresh Drop all tables and re-run all migrations.
migrate:refresh Reset and re-run all migrations.
migrate:reset Rollback all database migrations
migrate:rollback Rollback the last database migration.
You can also view all available commands in artisan by typing following command.
list It is used lists all commands available.
php artisan list
To view the version of laravel you can run following command
php artisan -V
To get help on any of the command we can use -help parameter. for example to get the help for make:controller command we will execute
php artisan make:controller -help