Cheat Sheet Laravel



The Laravel Cheat Sheet is a new project from the EST Group that shows you many of the Laravel features from a filterable web app. For those that have used Laravel for a few years, you may notice the similarities to Jesse O’Briens. Jesse hasn’t had time to keep his version up to date which left an opening for this new one. Laravel Cheat Sheet Artisan php artisan -help OR -h php artisan -quiet OR -q php artisan -version OR -V php artisan -no-interaction OR -n php artisan -ansi php artisan -no-ansi php artisan -env // -v vv vvv Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug.

Introduction

Laravel Cheat Sheet Artisan // Displays help for a given command: php artisan -help OR -h // Do not output any message: php artisan -quiet OR -q // Display this application version: php artisan -version OR -V // Do not ask any interactive question. Laravel Cheat Sheet. GitHub Gist: instantly share code, notes, and snippets.

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.

Cheatsheet

Laravel commands:

laravel new project-name

This 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 commands:

composer require vendor/package

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.

composer update

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’t any breaking changes between versions that need to be addressed.

composer dump-autoload

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.

Artisan commands:

php artisan list

Lists all the artisan commands, run it and have a read!

php artisan --help OR -h

Displays some basic help, add --help or -h after any of these commands to see the help text with all available flags and options.

php artisan key:generate

This 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.

Laravel

php artisan --version OR -V

Displays your current version of Laravel, something like:

php artisan down

Puts your application into maintenance mode — visitors to the site will see a maintenance message.

php artisan up

Brings your application back out of maintenance mode.

php artisan env

Displays the current environment for your application, e.g.

php artisan route:list

Lists all the routes registered in your application, under the following headers:

php artisan serve --host=192.168.1.100 --port=80

Runs 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:auth

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.

php artisan make:model ModelName -mcr

Creates 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 --migration

Creates a new database migration file for the model.

-c OR --controller

Creates a new controller file for the model.

-r OR --resource

Indicates if the generated controller should be a resource controller .

php artisan make:controller ControllerName

Creates 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 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).

php artisan migrate:rollback --step=5

This example will roll back the last 5 migrations.

php artisan migrate:reset

Rolls back all migrations.

Cheat Sheet Level 2310 Candy Crush

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 to your own project’s folders for additional configuration or customisation.

php artisan config:cache

Speed up your application for production by combining all your config options into a single file that loads quickly.

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 config:clear

Clear 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.

Cheat sheet level 2310 candy crush


I often have to quickly set up an AWS Lightsail instance and deploy a Laravel project to it. The process is pretty straightforward, but still, I usually forget where to find some files or which commands exactly to execute.

Here is a complete cheat sheet for setting up an AWS Lightsail Instance, deploying Laravel to it, and setting up the domain and SSL certificate.

I will assume that you have already created an Instance using LAMP as an image, created a public IP address, and attached it.

1. Update the instance

Cheat sheet laravel tutorialCheat

2. Install NPM

In case NPM is not installed yet:

3. Prepare the folder for your Laravel project:

4. Get the files of your laravel project.

In this example, I am using Git.

5. Install Composer and NPM dependencies

6. Set up proper files permissions

7. Get your application password

8. Create a MySQL Database and user

I will assume you are using MySQL 8, as shipped with the default LAMP image.

In case you want to be able to connect to MySQL from outside your Lightsail instance, you need to do the following steps:

  1. Open the port 3306 on the Lightsail Firewall
  2. In the file /opt/bitnami/mysql/my.cnf, comment out the line that starts with “bind-address”
  3. Restart MySQL with sudo /opt/bitnami/ctlscript.sh restart mysql

9. Set up your .env

Go back to your project folder

Copy the user and password, making sure you use ‘localhost' on DB_HOST:

Generate the key:

And finally, run the migration:

10. Set up the Virtual Host

Create the /opt/bitnami/apache2/conf/vhosts/<YOUR-APP-FOLDER-NAME>-vhost.conf and put this onto it:

Do the same now with /opt/bitnami/apache2/conf/vhosts/<YOUR-APP-FOLDER-NAME>-https-vhost.conf:

And restart Apache

By now, your Laravel project should be working if you browse to the public IP address of your instance.

11. Use a domain

Point the domain or subdomain you want to use to your instance’s public IP and change the APP_URL of the Laravel’s .env file.

By now, your Laravel project should be working if you browse to the domain you chose but without SSL certificate.

Cheat Sheet Level 664 Candy Crush Soda Saga

12. Generate an SSL certificate.

I will just copy here the needed commands based on this article: Tutorial: Using Let’s Encrypt SSL certificates with your LAMP instance in Amazon Lightsail

Now you will have to add one or two TXT entries to your domain. Make sure each TXT entries are already visible before continuing by using this tool: https://mxtoolbox.com/TXTLookup.aspx.

If you are not using CloudFront to configure the redirection from HTTP to HTTPS as I usually do, read the section about configuring this redirection on the article I linked before.

Cheat Sheet Laravel Tutorial

Restart Apache, and you should be ready to go.

Finally, do not forget to harden your server if you will use it on production!

Updated: 22.10.2020

–Sources:

Looking for a developer job?

--
Follow me on Twitter: @asanchezdev