How to Clear cache in Laravel

How to Clear cache in Laravel

Now we are going to learn, how to clear cache in Laravel. Command - php artisan cache:clear. Basically, there are two ways to clear the cache in Laravel. It will remove all the cache associated with the connection to the database.

If you’re facing this challenge not to worry as we’re going to discuss the Laravel clear cache command which can be used via Artisan in resolving this issue.

Read This Link : How to force redirect HTTP to HTTPS in Laravel 6.x, 7.x and 8.x and more

Laravel’s Artisan CLI enables you to clear cache not just from the view but also the route, config as well as others. Let's look at the example with the command-line interface (CLI) as well as with Route.

How to Clear cache in Laravel

As we discussed, Basically, there are two ways to clear the cache in Laravel.

Loading...
  • Using the CLI - command-line interface.
  • Using Routs with URL.

Using the CLI - command-line interface

In simple terms, Artisan is Laravel’s command-line interface (CLI) which allows you to better manage your web application’s code.

Buy Now Laravel Project With Admin Dashboard

Here you can issue the commands to clear cache as followings:

Clear Config Cache

Simply you can use config:clear to clear the config cache of the Laravel application.

 $ php artisan config:clear

Clear Application Cache

Run the following command to clear the application cache of the Laravel application.

Loading...
 $ php artisan cache:clear 

Clear Route Cache

Use the below command and clear your routes cache.

 $ php artisan route:clear 

Clear Compiled View Files

Sometimes you may need to clear compiled view files of your Laravel application. To clear compiled view files run the following command from the terminal.

Read This also: How to force redirect HTTP to HTTPS in Laravel 7.x and 6.x and more

 $ php artisan view:clear 

Fastest Blogger Template For Free

Using Routs with URL (Production Server)

After deploying our Laravel project in the production server, we can clear the cache of the project by using the URL. Most of the shared hosting providers don’t provide SSH access to the systems. In that case, you can clear the Laravel cache by calling the URL in the browser.

Loading...

Free Youtube Thumbnail Generator

In this concept, you can simply place the below code in your routes/web.php file of the Laravel application. Then access this URL in the browser to clear the cache of the Laravel application.

 Route::get('/clear-cache', function() {
Artisan::call('cache:clear');
return "Cache is cleared"; // you can replce your redirect
});

You can add more command into the same Route fucntion. ie:

Route::get('/clear-cache', function() {  
Artisan::call('cache:clear');
Artisan::call('view:clear');
return "Cache is cleared"; // you can replce your redirect
});

Conclusion

I hope this example is very helpful for you and your Laravel project. In this article, we have discussed all types of cache in Laravel as well as different ways to clear the cache of the Laravel project.

Thank you for reading.

Loading...

Related posts

Write a comment