Laravel clear cache (All Methods)

Laravel, one of the most widely used PHP framework. In this compact article we learn how to clear laravel cache by using terminal and browser. Laravel uses different types of cache for the application. When we made changes in the code then we have to clear caches for applying changes.

Laravel clear cache using Terminal

For this method you need the command line access of your web server. Because we have to navigate to the laravel project folder and run some commands from the terminal in this method.

At the very first step, Goto the laravel project directory using the cd command.

cd /path_to_your_laravel_application_folder/

1 : Clear Configuration Cache

Laravel combine all of the configuration files into a single, cached file. However you can clear the configuration cache by running the below command from terminal.

php artisan config:clear

2 : Clear Route Cache

For large application with many routes, Laravel uses route cache. You can clear the route cache by running the below command.

php artisan route:clear

3 : Clear Blade view Cache

Run the below command to clear all the pre-compiled Blade views.

php artisan view:clear

4 : Clear Application Cache

To clear the application cache of the Laravel application run the below command.

php artisan cache:clear

Clear Laravel cache using Browser

On the shared hosting servers, we do not having SSH access. In that case you can use the laravel routes to clear caches. Simply create the routes and point your browser to that URL for run the command.

For simple example, Goto the web.php file in your laravel project folder and add the below code in that file.

For example, if you want to clear the config cache. Then visit the following URL in your web browser, remember to replace the mydomain with your servers IP or Domain name.

http://mydomain/config-cache

 //Clear config cache:
 Route::get('/config-cache', function() {
     $exitCode = Artisan::call('config:clear');
     return 'Config cache cleared';
 }); 

 //Clear route cache:
 Route::get('/route-cache', function() {
     $exitCode = Artisan::call('route:clear');
     return 'Routes cache cleared';
 });

  // Clear view cache:
 Route::get('/view-cache', function() {
     $exitCode = Artisan::call('view:clear');
     return 'View cache cleared';
 });

 // Clear application cache:
 Route::get('/clear-cache', function() {
     $exitCode = Artisan::call('cache:clear');
     return 'Application cache cleared';
 });

Leave a Comment