Laravel Commands Cheatsheet

ยท 1318 words ยท 7 minute read

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.

composer update ๐Ÿ”—

update the installed packages.

composer dump-autoload ๐Ÿ”—

updates your 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

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 /register or /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.

flagmeaning
-m or --migrationcreates a new database migration file for the model
-c or --controllercreates a new controller file for the model
-r or --resourcesindicates 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

Cache ๐Ÿ”—

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.

Config ๐Ÿ”—

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.

database (db) ๐Ÿ”—

php artisan db:seed ๐Ÿ”—

seed the database with records.

php artisan db:wipe ๐Ÿ”—

delete / drop all tables, views, and types.

Event ๐Ÿ”—

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.

make commands ๐Ÿ”—

php artisan commandmeaning
make:channelCreate a new channel class
make:commandCreate a new Artisan command
make:componentCreate a new view component class
make:controllerCreate a new controller class
make:eventCreate a new event class
make:exceptionCreate a new custom exception class
make:factoryCreate a new model factory
make:jobCreate a new job class
make:listenerCreate a new event listener class
make:mailCreate a new email class
make:middlewareCreate a new middleware class
make:migrationCreate a new migration file
make:modelCreate a new Eloquent model class
make:notificationCreate a new notification class
make:observerCreate a new observer class
make:policyCreate a new policy class
make:providerCreate a new service provider class
make:requestCreate a new form request class
make:resourceCreate a new resource
make:ruleCreate a new validation rule
make:seederCreate a new seeder class
make:testCreate a new test class

migrate commands ๐Ÿ”—

php artisan commandmeaning
migrate:freshDrop all tables and re-run all migrations
migrate:installCreate the migration repository
migrate:refreshReset and re-run all migrations
migrate:resetRollback all database migrations
migrate:rollbackRollback the last database migration
migrate:statusShow 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

queue commands ๐Ÿ”—

php artisan commandmeaning
queue:failedList all of the failed queue jobs
queue:failed-tableCreate a migration for the failed queue jobs database table
queue:flushFlush all of the failed queue jobs
queue:forgetDelete a failed queue job
queue:listenListen to a given queue
queue:restartRestart queue worker daemons after their current job
queue:retryRetry a failed queue job
queue:tableCreate a migration for the queue jobs database table
queue:workStart processing jobs on the queue as a daemon

route commands ๐Ÿ”—

php artisan commandmeaning
route:cacheCreate a route cache file for faster route registration
route:clearRemove the route cache file
route:listList all registered routes

php artisan schedule:run ๐Ÿ”—

Run the scheduled commands.

php artisan session:table ๐Ÿ”—

Create a migration for the session database table.

Create the symbolic links configured for the application.

php artisan stub:publish ๐Ÿ”—

Publish all stubs that are available for customization.

view commands ๐Ÿ”—

commandmeaning
php artisan view:cacheCompile all of the application’s Blade templates
php artisan view:clearClear 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 .zshrc or .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.

Share:
waffarx cash back