
Good content takes time and effort to come up with.
Please consider supporting us by just disabling your AD BLOCKER and reloading this page again.
Most of the time you may end up refreshing your view pages or adding new routes but it won't be accessible from the user browser. It's all because of caching that Laravel does for us.
In this article let's see how to clear Laravel application cache, routes, views & configs caches in a very simple way.
Topics that we will cover
In Laravel 8 you can run the following command and breath easily.
php artisan optimize:clear
Flush the application cache
php artisan cache:clear
Remove the route cache file
php artisan route:clear
Clear all compiled view files
php artisan view:clear
Remove the configuration cache file
php artisan config:clear
We can create a simple callback URL in web.php
to clear all the caches at a stretch
Route::get('/clear-all-cache', function() {
Artisan::call('cache:clear');
Artisan::call('route:clear');
Artisan::call('view:clear');
Artisan::call('config:clear');
echo "Cleared all caches successfully.";
});
Let's create a simple command utility so that we can use it as and when required from the command line.
ClearAllCache
Commandphp artisan make:command ClearAllCache
ClearAllCache.php
command class<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Artisan;
class ClearAllCache extends Command
{
protected $signature = 'cache:clear-all';
protected $description = 'Command to clear application, route, view & config caches';
public function handle()
{
Artisan::call('cache:clear');
Artisan::call('route:clear');
Artisan::call('view:clear');
Artisan::call('config:clear');
echo "Cleared all caches successfully.";
}
}
You can verify the above command using the following in the console
php artisan
I hope this article helped you. Please share it with your friends.
Add Google ADS In AMP (Accelerated Mobile Pages) Website
Run Raw Queries Securely In Laravel
Laravel 7.x Multiple Database Connections, Migrations, Relationships & Querying
Sass or SCSS @function vs @mixin
SummerNote WYSIWYG Text Editor
URL Redirects From Called Functions In Laravel
Plain PHP Resumable Large File Uploads In Chunks Using FlowJs
Create Zip File On The Fly With Streaming Download In PHP Laravel
Securely SSH Your Server & Push Files With FileZilla
Facebook Login With PHP Laravel Socialite
Custom Validation Rules In PHP Laravel (Using Artisan Command)
Multiple GIT Key Pairs Or Account In The Same Computer
Free SSL Certificate With Lets Encrypt/Certbot In Linux (Single / Multiple Domains)