Laravel gives developers a Command Line interface - Artisan. Artisan commands line tool is very handy for building a Laravel application. With this command-line tool, we can make models, controllers, and can do data migrations, and many more.
Here is the list of frequently used and must know Laravel artisan commands (cheat sheet).
Create a new Laravel project (first, install composer in your system)
composer create-project laravel/laravel example-app
Laravel installer as a global Composer dependency
The Laravel installer is simple and easy.
laravel new example-app
Generate a unique key to your application in
php artisan key:generate
Create a front-end scaffolding with Bootstrap flag
php artisan ui bootstrap
Similarly, we can create a front-end scaffolding for other frontends UIs as below
Create a front-end scaffolding with Vuejs
php artisan ui vue
Create a front-end scaffolding with React
php artisan ui react
Starting Development Server
php artisan serve
make:xxx command to create models, controllers, migrations, Jobs, provider, and requests, etc.
Here are the available
make:xxx commands -
To view all the available laravel artisan command list
php artisan list
Lists all the routes registered in the application
php artisan route:list
Create a migration table
php artisan make:migration create_post_table
Run migrations or any pending database migrations.
php artisan migrate
php artisan make:seeder PostSeeder
php artisan db:seed --class=PostSeeder
Rolls back the latest database migration
(Note: You must have the necessary commands in your down() function of the migration).
php artisan migrate:rollback
Rollback the last n migrations.
php artisan migrate:rollback --step=3
Rollback all migrations and re-create database with seeders
php artisan migrate:refresh --seed
Create laravel authentication
This simple auth command creates ready to use routes and views (registration and login) required for authentication. You need to run migration after this command.
php artisan make:auth
Enabling maintenance mode
php artisan down
Disabling Maintenance Mode
php artisan up
Clear Application Cache
php artisan cache:clear
Clear Config Cache
php artisan config:clear
Clear Route Cache
php artisan route:clear
Clear Compiled View Files
php artisan view:clear
Clear all Laravel's cache in one command
(Compiled views, Application cache, Route cache, Configuration cache, etc.)
php artisan optimize:clear
There is too much to learn and sometimes we all lose interest at some point. Be it long-running projects or repetitive tasks or just bad weather 😅.
Well, don't be! Laravel inspire command is here -
php artisan inspire