<-- Back to The Cleavr Slice

13 June 2023

Laravel

Exploring the Laravel Quick Commands

Cleavr comes pre-loaded with Laravel focused Quick Commands that can be ran for your production Laravel projects.

But...

Have you ever wondered what they are all for?

Many of the commands are pretty straightforward. Though, there may be some that you aren't exactly clear what the purpose is...

In this blog post, we'll simply go through the different commands and their purpose. Please feel free to use this as your cheat sheet!

Cache commands

Caching is a great way to make your web applications run faster and smoother. With these cache commands, you can easily manage the cache of your production site.

Artisan config cache

Caching your configuration files into a single file can help your application run faster. To do this, use the php artisan config:cache command. This will combine all of your configuration options into one file which will be quickly loaded by the framework. It's a great idea to run the php artisan config:cache command as part of your production deployment process for optimal performance.

php artisan config:cache

Artisan cache clear

The cache clear command will clear out all items from the cache, no matter which cache driver you are using.

php artisan cache:clear

If you'd like to target a particular store, you can use a quick command with a flag to do so. For example, php artisan cache:clear --store redis will clear the redis cache store only.

Furthermore, if you need to clear specific items, you can use the tags flag, like this: php artisan cache:clear --tags=tag1,tag2.

Artisan event clear

If you're using Events in your Laravel application, it's a good idea to cache them for improved performance. The event:clear command can be used to delete your cached Events and rebuild the cache. This is a great way to keep your application running smoothly.

php artisan event:clear

Remove route cache

Caching your routes is a great way to speed up your application's route registration process. If you've added a new route and want to make sure it's registered, you can clear the route cache on the server by running the php artisan route:clear command.

php artisan route:clear

Remove the cached bootstrap files

Laravel makes it easy for you to reset all the caches we've discussed by using a single Artisan command. This is a great way to quickly clear all the caches in your application, without having to run multiple commands.

php artisan optimize:clear

Queue commands

Artisan queue clear

If you're looking to remove all jobs from the default queue and connection, you can easily do so using the queue:clear command.

php artisan queue:clear

You can also create a new quick command and target a specific queue and connection, such as with the following which will target the email queue in redis - php artisan queue:clear redis --queue=emails.

Artisan queue failed

If you're looking to see which jobs have failed, running the queue:failed command will show you the job ID, connection, queue, failure time and other details about the failed jobs that appear in the failed_jobs database table.

php artisan queue:failed

Flush failed queue jobs

Running queue:flush command removes all of the failed jobs from the failed_jobs table.

php artisan queue:flush

Laravel Horizon commands

If you are using Laravel Horizon for your project, which is a Redis-centric dashboard, then you can use the following commands to help manage Horizon.

Pause Horizon

If you need to pause the Horizon process, run the horizon:pause command.

php artisan horizon:pause

Continue Horizon

When you're ready to continue processing jobs, run the horizon:continue command.

php artisan horizon:continue

Check Horizon status

If you'd like to know the current status of Horizon, run horizon:status to check.

php artisan horizon:status

Clear Horizon status

If you would like to clear all jobs from your application's default queue, run the horizon:clear command.

php artisan horizon:clear

Miscellaneous commands

Artisan view clear

It's a good idea to clear the compiled view files of your Laravel application every now and then. To do this, run the view:clear command.

php artisan view:clear

Artisan clear compiled

This command is used to remove the compiled class files from the framework, which are stored in the bootstrap/cache/ directory. By running this command, compiled.php and services.php will both be removed from the directory.

php artisan clear-compiled

Artisan env

Running this command will display what environment-mode the Laravel application is running in; ie: development, staging, production.

php artisan env

Take control of your servers and deployments.Without breaking a sweat.

Sign up for a 5-day free trial of Cleavr Pro. No credit card required until you decide to subscribe.

Sign up for free