What the F*ck Is With All the Artisan Commands: Quickies
As I’ve been organizing the flow of this series there’s a random set of commands that don’t really have a good home. I thought I would cover them now so they’re out of the way.
list
The list
command displays all of the registered commands that artisan has available.
ubuntu@ubuntu-xenial:/var/www$ php artisan list
Laravel Framework 6.2.0
Usage:
command [options] [arguments]
Options:
-h, --help Display this help message
-q, --quiet Do not output any message
-V, --version Display this application version
--ansi Force ANSI output
--no-ansi Disable ANSI output
-n, --no-interaction Do not ask any interactive question
--env[=ENV] The environment the command should run under
-v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
Available commands:
** Snip **
view
view:cache Compile all of the application's Blade templates
view:clear Clear all compiled view files
Please note: I have snipped out a huge section in the middle of this for berevity. The full list can be found at http://www.thisprogrammingthing.com/what-the-f-ck-is-with-all-the-artisan-commands-intro/
Why It Exists
The list
command exists to give a full list of the available artisan commands.
When Should You Use It
When you can’t quite remember the name of a command, list
will let you read them all so you can remember.
help
The help command shows help information for a specific command.
ubuntu@ubuntu-xenial:/var/www$ php artisan help migrate
Description:
Run the database migrations
Usage:
migrate [options]
Options:
--database[=DATABASE] The database connection to use
--force Force the operation to run when in production
--path[=PATH] The path(s) to the migrations files to be executed (multiple values allowed)
--realpath Indicate any provided migration file paths are pre-resolved absolute paths
--pretend Dump the SQL queries that would be run
--seed Indicates if the seed task should be re-run
--step Force the migrations to be run so they can be rolled back individually
-h, --help Display this help message
-q, --quiet Do not output any message
-V, --version Display this application version
--ansi Force ANSI output
--no-ansi Disable ANSI output
-n, --no-interaction Do not ask any interactive question
--env[=ENV] The environment the command should run under
-v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
Why It Exists
The help
command exists to give a full list of the available options for a given command.
When Should You Use It
When you need to see the available options for a specific command.
inspire
The inspire
command lists an inspirational quote.
ubuntu@ubuntu-xenial:/var/www$ php artisan inspire
It is quality rather than quantity that matters. - Lucius Annaeus Seneca
ubuntu@ubuntu-xenial:/var/www$ php artisan inspire
Act only according to that maxim whereby you can, at the same time, will that it should become a universal law. - Immanuel Kant
ubuntu@ubuntu-xenial:/var/www$ php artisan inspire
Simplicity is an acquired taste. - Katharine Gerould
ubuntu@ubuntu-xenial:/var/www$ php artisan inspire
Simplicity is the essence of happiness. - Cedric Bledsoe
Why It Exists
The command will help you feel better.
When Should You Use It
Any time you need a pick me up.
env
The env
command displays the current application environment.
ubuntu@ubuntu-xenial:/var/www$ php artisan env
Current application environment: local
Why It Exists
No idea.
When Should You Use It
No idea again. You could always open the “.env” so I fail to see the benefit of this command.
key:generate
When you initially create your Laravel application the “.env” file starts out like the following:
APP_NAME=Laravel
APP_ENV=local
APP_KEY=
APP_DEBUG=true
APP_URL=http://localhost
When you attempt to do anything you’ll receive the following error message:
No application encryption key has been specified.
To fix this you’ll need to run the key:generate
command.
ubuntu@ubuntu-xenial:/var/www$ php artisan key:generate
Application key set successfully.
Now if you check your “.env” file the APP_KEY will have a value and you won’t receive the “No application encryption key has been specified.” exception.
Why It Exists
The APP_KEY environmental variable is used by the encrypt()
and decrypt()
functions as the input to generate encryption keys.
Here’s a quick example of how easy it is to encrypt and decrypt your data:
$encrypted = encrypt("test string");
echo $encrypted, PHP_EOL, PHP_EOL;
echo decrypt($encrypted), PHP_EOL;
Output:
eyJpdiI6IllLOFNYcmE5R3lCbjFqVEpvVzFKZkE9PSIsInZhbHVlIjoiSlZIM2RvYlQ0c25Eb21UMEx0Wk1mTjdJdkNMZDhHVjVsN3Y2T0diY2FyRT0iLCJtYWMiOiIzNjQwMWE4MzgwNWNlMWY1NDRmYzg4YjdmOTFmMDdlMDNkZTUxYmVjMzgxOTExZDQ4Njk4NTYwNGUwMTdiZTAwIn0=
test string
When Should You Use It
When you initially create your application and then never again because running it a second time creates a new key and prevents you from decrypting your data.
up/down
The up
and down
commands exist in order to place your application into maintenance mode (down
) and bring it back out of maintenance mode (up
).
Here’s a quick example.
ubuntu@ubuntu-xenial:/var/www$ php artisan down
Application is now in maintenance mode.
Now if we try to access our application we get a “service unavailable” message.
ubuntu@ubuntu-xenial:/var/www$ php artisan up
Application is now live.
Why It Exists
To place your application into maintenance mode and bring it back.
When Should You Use It
When you need to perform a large change to your database or server and don’t want people trying to make changes that might be lost.
Hopefully this has been as helpful to you as it has to me and check back soon for more artisan commands.
Scott Keck-Warren
Scott is the Director of Technology at WeCare Connect where he strives to provide solutions for his customers needs. He's the father of two and can be found most weekends working on projects around the house with his loving partner.
Top Posts
- Working With Soft Deletes in Laravel (By Example)
- Fixing CMake was unable to find a build program corresponding to "Unix Makefiles"
- Upgrading to Laravel 8.x
- Get The Count of the Number of Users in an AD Group
- Multiple Vagrant VMs in One Vagrantfile
- Fixing the "this is larger than GitHub's recommended maximum file size of 50.00 MB" error
- Changing the Directory Vagrant Stores the VMs In
- Accepting Android SDK Licenses From The OSX Command Line
- Fixing the 'Target class [config] does not exist' Error
- Using Rectangle to Manage MacOS Windows