Laravel Commands Cheatsheet
laravel new project-name
create a new folder named “project-name” in the current directory. Then create all necessary Laravel project files inside it.
composer require vendor/package
update composer.json with the necessary details of the package you are choosing to install, then install the package in your project.
update the installed packages.
vendor/composer/autoload_classmap.php file. You have to run this command if you have a new class in your project that has not yet been loaded.
php artisan list
list all the artisan commands
php artisan --help or
php artisan -h
display some basic help.That shows all/some the available flags for
php artisan key:generate
generates a new key and adds it to your
.env file. A key is automatically generated and added to
.env file when you use
laravel new projectName. But it is useful when you clone an existing project. This app key is mainly ised for encrypting cookies.
php artisan --version or
php artisan -V
displays your current version of Laravel.
php artisan down
puts your application into maintenance mode. Visitors will see the maintenance message.
php artisan up
brings your application (website) back out of maintenance mode.
php artisan env
displays the current environment for your application (website) like this
Current application environment:local
php artisan route:list
lists all the routes registered in your application, under the following headers:
Domain, Method, URI, Name, Action, Middelware
php artisan serve
runs a local web server and tells you the local url to use to show the website / application. If you want to specify a port and host use a command like this
php artisan serve --host=192.168.1.200 --port=80.
php artisan make:auth
creates all that is necessary for authentication in your application. Make sure you run
php artisan migrate after this command. After that, you can navigate to
/login on your project to create and log in an account.
php artisan make:model ModelName -mcr
creates a model class and file in your project. You can use some, none or all of the
-mcr flags when creating a new model.
|creates a new database migration file for the model|
|creates a new controller file for the model|
|indicates if the generates controller should be a resource controller|
If you want to see all options, run this command
php artisan make:model -h.
php artisan make:controller ControllerName
creates a controller file in your project. You can specify a controller for which model via this flag
--model=ModelName so the command will be
php artisan make:controller UserController --model=User if the
User is the name of a model.
php artisan make:migration --table='table' 'description_of_migration'
creates a database migration file that you can edit to add necessary table properties.
php artisan migrate
runs any pending database migrations.
php artisan migrate:rollback
Rolls back the latest database migration (ensuring you have the necessary commands in your
down() function of the migration).
if you want to roll back the last 5 migrations, just use this command
php artisan migrate:rollback --step=5.
php artisan migrate:reset
rolls back all migrations.
php artisan vendor:publish
displays a list of vendor packages installed in your project, giving you the option to specify which you would like to copy the configuration or view files toyour own project’s folders for additional configuration or customization.
php artisan route:cache
speed up your application for production caching all your application’s routes.
php artisan route:clear
clear the cached version of your routes — use this on local deployments if you have cached routes. Re-run the cache command above on production to clear and re-cache routes.
php artisan clear-compiled
remove the compiled class file.
php artisan optimize
cache the framework bootstrap files.
php artisan test
run the application tests.
php artisan tinker
interact with your application.
php artisan auth:clear-resets
flush expired password reset tokens
php artisan cache:clear
flush the application cache.
php artisan cache:forget
remove an item from the cache.
php artisan cache:table
create a migration for the cahce database table.
php artisan config:cache
create a cache file for faster configuration loading. That speeds up your application for production by combining all your config options into a single file that loads quickly.
php artisan config:clear
removes / clears your cached config (configuration cache file)—use this on local deployments if you have cached config. Re-run the cache comman above on production to clear and re-cache config.
php artisan db:seed
seed the database with records.
php artisan db:wipe
delete / drop all tables, views, and types.
php artisan event:cache
discover and cache the application’s events and listeners.
php artisan event:clear
clear all cached events and listeners.
php artisan event:generate
generate the missing events and listeners based on registration.
php artisan event:list
list the application’s events and listeners.
|Create a new channel class|
|Create a new Artisan command|
|Create a new view component class|
|Create a new controller class|
|Create a new event class|
|Create a new custom exception class|
|Create a new model factory|
|Create a new job class|
|Create a new event listener class|
|Create a new email class|
|Create a new middleware class|
|Create a new migration file|
|Create a new Eloquent model class|
|Create a new notification class|
|Create a new observer class|
|Create a new policy class|
|Create a new service provider class|
|Create a new form request class|
|Create a new resource|
|Create a new validation rule|
|Create a new seeder class|
|Create a new test class|
|Drop all tables and re-run all migrations|
|Create the migration repository|
|Reset and re-run all migrations|
|Rollback all database migrations|
|Rollback the last database migration|
|Show the status of each migration|
php artisan notifications:table
creates a migration for the notifications table.
php artisan optimize:clear
Remove the cached bootstrap files
php artisan package:discover
Rebuild the cached package manifest
|List all of the failed queue jobs|
|Create a migration for the failed queue jobs database table|
|Flush all of the failed queue jobs|
|Delete a failed queue job|
|Listen to a given queue|
|Restart queue worker daemons after their current job|
|Retry a failed queue job|
|Create a migration for the queue jobs database table|
|Start processing jobs on the queue as a daemon|
|Create a route cache file for faster route registration|
|Remove the route cache file|
|List all registered routes|
php artisan schedule:run
Run the scheduled commands.
php artisan session:table
Create a migration for the session database table.
php artisan storage:link
Create the symbolic links configured for the application.
php artisan stub:publish
Publish all stubs that are available for customization.
|Compile all of the application’s Blade templates|
|Clear all compiled view files|
Final thoughts & tips
I personally add an alias for
php artisan because I have to write it again and again. I just add this line to the end of my
.bashrc on my Linux or Mac.
alias pa="php artisan"
So, I can write
pa serve which means
php artisan serve.
If you have any recommendations or tips or questions for me, tweet to me on twitter. And if you found this post useful, recommend it to a friend or share it with him/her.