The key:generate command is used to generate a random key. This command will update the key stored in the application's environment file. The command also supports an optional --show flag. Specifying this flag will simply show the generated key instead of updating any configuration or environment files.

The following example demonstrates how to update/change the application's key:

1php artisan key:generate

#Regenerating the Application Key

It is important to note that if the encryption key needs to be regenerated after an application has been in use, any data that was previously encrypted using the old key cannot be decrypted using the new encryption key. While regenerating the encryption key is not recommended, there are some scenarios where it is beneficial, if not absolutely critical to do so.
When these scenarios arise, the problems can be overcome by decrypting the old data and reapplying the encryption using the new encryption key.

The following example will simply display the generated key instead of generating it:

1php artisan key:generate --show

The output will be similar to the following, but the key will most likely be different:

1base64:lg1m/12MHBbBpiWTXjot98Q9MP/nSzPrvLEU2beD+2Y= Laravel Artisan Migration Command: The migrate:install Command

The migrate:install command creates a migrations database table in Laravel. You can specify the database connection to u...

Read more Laravel Artisan Migration Command: The migrate:refresh Command

Learn how to reset and run all outstanding migrations using the migrate:refresh command in Laravel. This command is a co...

Read more Laravel Artisan Migration Command: The migrate:reset Command

Learn how to use the migrate:reset command in Laravel to roll back all the migrations in your application. Customize the...

Read more Laravel Artisan Migration Command: The migrate:rollback Command

Learn how to use the migrate:rollback command in Laravel to undo the last database migration. This command supports vari...

Read more