Laravel Clear Cache Programmatically & Artisan Command

Laravel Clear Cache Programmatically & Artisan Command

To clear the cache programmatically and artisan commands in Laravel applications Use a facade of cache to clear all types of caches programmatically, and you can also use different php artisan commands to clear the cache of routes, config, app, and views.

Option 1: Clear Cache Programmatically in Laravel

Simply use laravel cache facade to remove or clear all types of caches like config, route, views, etc from laravel applications.

Here is the code to programmatically clear Laravel’s cache:

use Illuminate\Support\Facades\Cache;
 
Cache::flush();

Option 2: Clear Cache using Artisan Command in Laravel

You can clear or delete the cache of configurations, routes, views, etc. from Laravel projects using the command line interface, as you will find some commands using which you can clear any type of cache from Laravel’s apps.

Run php artisan route:cache command on cmd or command line to clear the route cache in Laravel:

php artisan route:cache

Run php artisan cache:clear command on cmd or command line to clear the application cache in Laravel:

php artisan cache:clear

To clear the config cache in Laravel, run php artisan config:cache command on cmd or command line:

php artisan config:cache

To clear the view cache in Laravel, run php artisan view:clear command on cmd or command line:

php artisan view:clear

Conclusion

That’s it; you have learned how to clear programmatically and using artisan command to clear all types of cache from laravel applications.

Recommended Laravel Tutorials

Recommended:-Laravel Try Catch

AuthorAdmin

Greetings, I'm Devendra Dode, a full-stack developer, entrepreneur, and the proud owner of Tutsmake.com. My passion lies in crafting informative tutorials and offering valuable tips to assist fellow developers on their coding journey. Within my content, I cover a spectrum of technologies, including PHP, Python, JavaScript, jQuery, Laravel, Livewire, CodeIgniter, Node.js, Express.js, Vue.js, Angular.js, React.js, MySQL, MongoDB, REST APIs, Windows, XAMPP, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL, and Bootstrap. Whether you're starting out or looking for advanced examples, I provide step-by-step guides and practical demonstrations to make your learning experience seamless. Let's explore the diverse realms of coding together.

2 replies to Laravel Clear Cache Programmatically & Artisan Command

  1. Thanks for this clear cache in laravel post, I have to clear the cache on shared using this article.

    All the commands for clear cache in laravel ars very useful for me.

    laravel clear cache shared hosting
    laravel clear cache config
    laravel clear cache command line
    laravel clear cache without artisan

    Thanks

  2. All in one

    Terminal:
    php artisan optimize:clear

    Application :

    Route::get(‘/clear-cache’, function() {
    Artisan::call(‘optimize:clear’);
    echo Artisan::output();
    });

Leave a Reply

Your email address will not be published. Required fields are marked *