{"id":751,"date":"2020-12-28T07:56:26","date_gmt":"2020-12-28T07:56:26","guid":{"rendered":"https:\/\/appfinz.com\/blogs\/?p=751"},"modified":"2020-12-28T07:56:28","modified_gmt":"2020-12-28T07:56:28","slug":"laravel-cheatsheets","status":"publish","type":"post","link":"https:\/\/www.appfinz.com\/blogs\/laravel-cheatsheets\/","title":{"rendered":"Laravel Commands Cheatsheet"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">Introduction<\/h2>\n\n\n\n<p>One of the great features of Laravel is its command line tool&nbsp;<a href=\"https:\/\/laravel.com\/docs\/5.7\/artisan\" target=\"_blank\" rel=\"noreferrer noopener\"><strong>artisan<\/strong><\/a>. It is effectively a powerful scripting tool that contains many built in commands to help you while you create your Laravel application.<\/p>\n\n\n\n<p>During development you may find yourself repeating a number of key commands, so we\u2019re going to go through some of the essential ones in this article. We\u2019re mostly focussing on artisan commands but there are a few others too that will be useful.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Cheatsheet<\/h2>\n\n\n\n<p><strong>Laravel commands:<\/strong><\/p>\n\n\n\n<p><code>laravel new project-name<\/code><\/p>\n\n\n\n<p>This will create a folder within the folder you are currently in named \u201cproject-name\u201d 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.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Composer commands:<\/strong><\/h3>\n\n\n\n<p><code>composer require vendor\/package<\/code><\/p>\n\n\n\n<p>This 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.<\/p>\n\n\n\n<p><code>composer update<\/code><\/p>\n\n\n\n<p>This 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\u2019t any breaking changes between versions that need to be addressed.<\/p>\n\n\n\n<p><code>composer dump-autoload<\/code><\/p>\n\n\n\n<p>This 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.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Artisan commands:<\/strong><\/h3>\n\n\n\n<p><code>php artisan list<\/code><\/p>\n\n\n\n<p>Lists all the artisan commands, run it and have a read!<\/p>\n\n\n\n<p><code>php artisan --help OR -h<\/code><\/p>\n\n\n\n<p>Displays some basic help, add&nbsp;<code>--help<\/code> or&nbsp;<code>-h<\/code> after any of these commands to see the help text with all available flags and options.<\/p>\n\n\n\n<p><code>php artisan key:generate<\/code><\/p>\n\n\n\n<p>This generates a new key and adds it to your&nbsp;.env file. A key is automatically generated when you run&nbsp;<code>laravel new project-name<\/code> but the command can be useful when cloning an existing project. This app key is mainly used for encrypting cookies.<\/p>\n\n\n\n<p><code>php artisan --version OR -V<\/code><\/p>\n\n\n\n<p>Displays your current version of Laravel, something like:&nbsp;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Laravel Framework 5.7.15\n<\/pre>\n\n\n\n<p><code>php artisan down<\/code><\/p>\n\n\n\n<p>Puts your application into maintenance mode\u200a\u2014\u200avisitors to the site will see a maintenance message.<\/p>\n\n\n\n<p><code>php artisan up<\/code><\/p>\n\n\n\n<p>Brings your application back out of maintenance mode.<\/p>\n\n\n\n<p><code>php artisan env<\/code><\/p>\n\n\n\n<p>Displays the current environment for your application, e.g.&nbsp;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Current application environment:local\n<\/pre>\n\n\n\n<p><code>php artisan route:list<\/code><\/p>\n\n\n\n<p>Lists all the routes registered in your application, under the following headers:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Domain, Method, URI, Name, Action, Middleware\n<\/pre>\n\n\n\n<p><code>php artisan serve --host=192.168.1.100 --port=80<\/code><\/p>\n\n\n\n<p>Runs a web server that will be accessible locally, if you do not specify a&nbsp;<code>--host<\/code> or a&nbsp;<code>--port<\/code> the site will be accessed at your local ip on port 8000.<\/p>\n\n\n\n<p><code>php artisan make:auth<\/code><\/p>\n\n\n\n<p>Creates 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.<\/p>\n\n\n\n<p><code>php artisan make:model ModelName -mcr<\/code><\/p>\n\n\n\n<p>Creates a model class and file in your project. You can use some, all or none of the&nbsp;<code>-mcr<\/code> flags when creating a new model. Run&nbsp;<code>php artisan make:model -h<\/code> to see the full set of options.<\/p>\n\n\n\n<p>These flags perform the following operations:<\/p>\n\n\n\n<p><code>-m OR --migration<\/code><\/p>\n\n\n\n<p>Creates a new database migration file for the model.<\/p>\n\n\n\n<p><code>-c OR --controller<\/code><\/p>\n\n\n\n<p>Creates a new controller file for the model.<\/p>\n\n\n\n<p><code>-r OR --resource<\/code><\/p>\n\n\n\n<p>Indicates if the generated controller should be a resource controller&nbsp;.<\/p>\n\n\n\n<p><code>php artisan make:controller ControllerName<\/code><\/p>\n\n\n\n<p>Creates a controller file in your project.<\/p>\n\n\n\n<p><code>php artisan make:migration --table='table' 'description_of_migration'<\/code><\/p>\n\n\n\n<p>Creates a database migration file that you can edit to add necessary table properties.<\/p>\n\n\n\n<p><code>php artisan migrate<\/code><\/p>\n\n\n\n<p>Runs any pending database migrations.<\/p>\n\n\n\n<p><code>php artisan migrate:rollback<\/code><\/p>\n\n\n\n<p>Rolls back the latest database migration (ensuring you have the necessary commands in your&nbsp;<code>down()<\/code> function of the migration).<\/p>\n\n\n\n<p><code>php artisan migrate:rollback --step=5<\/code><\/p>\n\n\n\n<p>This example will roll back the last 5 migrations.<\/p>\n\n\n\n<p><code>php artisan migrate:reset<\/code><\/p>\n\n\n\n<p>Rolls back all migrations.<\/p>\n\n\n\n<p><code>php artisan vendor:publish<\/code><\/p>\n\n\n\n<p>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 to your own project\u2019s folders for additional configuration or customisation.<\/p>\n\n\n\n<p><code>php artisan config:cache<\/code><\/p>\n\n\n\n<p>Speed up your application for production by combining all your config options into a single file that loads quickly.<\/p>\n\n\n\n<p><code>php artisan route:cache<\/code><\/p>\n\n\n\n<p>Speed up your application for production caching all your application\u2019s routes.<\/p>\n\n\n\n<p><code>php artisan route:clear<\/code><\/p>\n\n\n\n<p>Clear the cached version of your routes\u200a\u2014\u200ause this on local deployments if you have cached routes. Re-run the cache command above on production to clear and re-cache routes.<\/p>\n\n\n\n<p><code>php artisan config:clear<\/code><\/p>\n\n\n\n<p>Clear your cached config\u200a\u2014\u200ause this on local deployments if you have cached config. Re-run the cache command above on production to clear and re-cache config.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Laravel Cheatsheet<\/p>\n","protected":false},"author":1,"featured_media":752,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[21],"tags":[114,113],"class_list":["post-751","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-laravel","tag-laravel","tag-laravel-cheatsheet"],"_links":{"self":[{"href":"https:\/\/www.appfinz.com\/blogs\/wp-json\/wp\/v2\/posts\/751","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appfinz.com\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appfinz.com\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appfinz.com\/blogs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appfinz.com\/blogs\/wp-json\/wp\/v2\/comments?post=751"}],"version-history":[{"count":1,"href":"https:\/\/www.appfinz.com\/blogs\/wp-json\/wp\/v2\/posts\/751\/revisions"}],"predecessor-version":[{"id":753,"href":"https:\/\/www.appfinz.com\/blogs\/wp-json\/wp\/v2\/posts\/751\/revisions\/753"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.appfinz.com\/blogs\/wp-json\/wp\/v2\/media\/752"}],"wp:attachment":[{"href":"https:\/\/www.appfinz.com\/blogs\/wp-json\/wp\/v2\/media?parent=751"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appfinz.com\/blogs\/wp-json\/wp\/v2\/categories?post=751"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appfinz.com\/blogs\/wp-json\/wp\/v2\/tags?post=751"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}