Laravel Commands Cheatsheet
Speed up your Laravel app development with these useful commands
One of the great features of Laravel is its command line tool artisan. It is effectively a powerful scripting tool that contains many built in commands to help you while you create your Laravel application.
During development you may find yourself repeating a number of key commands, so we’re going to go through some of the essential ones in this article. We’re mostly focussing on artisan commands but there are a few others too that will be useful.
You can get a downloadable version of this cheatsheet by clicking here.
laravel new project-nameThis will create a folder within the folder you are currently in named “project-name” and create all the necessary Laravel project files here. Depending on how your environment is set up, you should be able to navigate to http://project-name.test in your browser and see the default Laravel welcome page.
composer require vendor/packageThis will update your composer.json with the necessary details of the package you are choosing to install and then install the package in your project.
composer updateThis will look for the newest versions of the packages you have installed and update them. You can manually update the Laravel version in your composer.json file and run this command to update your Laravel version, just make sure there aren’t any breaking changes between versions that need to be addressed.
composer dump-autoloadThis updates your vendor/composer/autoload_classmap.php file, you may need to run it if you have a new class in your project that has not yet been loaded.
php artisan listLists all the artisan commands, run it and have a read!
php artisan --help OR -hDisplays some basic help, add
-h after any of these commands to see the help text with all available flags and options.
php artisan key:generateThis generates a new key and adds it to your .env file. A key is automatically generated when you run
laravel new project-name but the command can be useful when cloning an existing project. This app key is mainly used for encrypting cookies.
php artisan --version OR -VDisplays your current version of Laravel, something like:
Laravel Framework 5.7.15
php artisan downPuts your application into maintenance mode — visitors to the site will see a maintenance message.
php artisan upBrings your application back out of maintenance mode.
php artisan envDisplays the current environment for your application, e.g.
Current application environment:local
php artisan route:listLists all the routes registered in your application, under the following headers:
Domain, Method, URI, Name, Action, Middleware
php artisan serve --host=192.168.1.100 --port=80Runs a web server that will be accessible locally, if you do not specify a
--host or a
--port the site will be accessed at your local ip on port 8000.
php artisan make:authCreates all that is necessary for authentication in your application. Make sure you run php artisan migrate after this command(see below), then you can navigate to /register or /login on your project to create and log in to an account.
php artisan make:model ModelName -mcrCreates a model class and file in your project. You can use some, all or none of the
-mcr flags when creating a new model. Run
php artisan make:model -h to see the full set of options.
These flags perform the following operations:
-m OR --migrationCreates a new database migration file for the model.
-c OR --controllerCreates a new controller file for the model.
-r OR --resourceIndicates if the generated controller should be a resource controller .
php artisan make:controller ControllerNameCreates a controller file in your project.
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 migrateRuns any pending database migrations.
php artisan migrate:rollbackRolls back the latest database migration (ensuring you have the necessary commands in your
down() function of the migration).
php artisan migrate:rollback --step=5This example will roll back the last 5 migrations.
php artisan migrate:resetRolls back all migrations.
php artisan vendor:publishDisplays 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 to your own project’s folders for additional configuration or customisation.
php artisan config:cacheSpeed up your application for production by combining all your config options into a single file that loads quickly.
php artisan route:cacheSpeed up your application for production caching all your application’s routes.
php artisan route:clearClear 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 config:clearClear your cached config — use this on local deployments if you have cached config. Re-run the cache command above on production to clear and re-cache config.
Like this story? Please follow us on Twitter.
At Welcm we design, develop and support touch screen applications and systems.
If you have a project you would like to discuss please send an enquiry from our contact page, email us at firstname.lastname@example.org or call us on 01252 950 650.
We also make Visitor Management Easy at https://welcm.ly
Originally published at welcm.uk.