Laravel clear route config view cache on server

How to remove cached config, route, view file in Laravel

To see all your routes compactly, you need to do:

php artisan route:list --compact

php artisan optimize will do the following tasks:

Image for post
Image for post

It clears the config cache, and re-cache it again. It also will clear route cache. and then re-cache routes and also files.

If you already did

php artisan route:cache

And want to clear cached routes, you need only to do:

php artisan route:clear

For config file you can do

php artisan config:clear

For view files you can do

php artisan view:clear


This directory is the place of all cached file in any Laravel project.


Removing this file will remove the routes cache on your server :


Another alternative:

You can assign clearing the cache file to a controller or running it internally.

You need only to put the following line in an action in a controller and call that method in one of your routes:


Optimizing Route Loading is a must on production :

The pros are pretty clear. After caching, your site gets faster.

If you are building a large application with many routes, you should make sure that you are running the route:cache Artisan command during your deployment process which will update the cached file.

You can run this command on the server:

php artisan route:cache

Or if you run the above command in your local you only need to upload this file bootstrap/cache/routes.php to your server.

Caching routes reduces all of your route registrations into a single method call within a cached file for improving the performance of route registration when registering hundreds of routes.

The cons of caching route are that once you cache the site’s routes, you have to re-cache your routes every time you make any changes to routes.php, or the changes won't show up.

Since this feature uses PHP serialization, you may only cache the routes for applications that exclusively use controller based routes. PHP is not able to serialize Closures.

Written by

Web geek, Self-taught full-stack web developer, Learning Python, Laravel, Vuejs, UX/UI design, Nuclear Physicist PhD

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store