Muhammad Yasir Amin

Loading websiteโ€ฆ

More from Muhammad Yasir Amin

Build Along With Me

Practical walkthroughs on Laravel, React, APIs and deployment workflows.

Subscribe on YouTube

Laravel 13 Clear Cache: optimize:clear, config:clear, route:clear and view:clear

๐Ÿ› ๏ธ Laravel Tutorials3 min read

Laravel 13 Clear Cache: optimize:clear, config:clear, route:clear and view:clear

Muhammad Yasir Amin

Muhammad Yasir Amin

Senior Full Stack Engineerโ€ขNov 8, 2026
Laravel 13 Clear Cache: optimize:clear, config:clear, route:clear and view:clear

To clear all cached framework files in Laravel 13, run php artisan optimize:clear. It removes the cached config, routes, views, events and compiled files in one step. For a single cache type, use cache:clear, config:clear, route:clear, view:clear or event:clear.

What do you need before you start?

  • Laravel 13 on PHP 8.3 or newer
  • Terminal access to the project root

Which cache clear commands exist?

  • php artisan cache:clear: flushes the application cache store (the data you stored with Cache::put())
  • php artisan config:clear: deletes the cached configuration file
  • php artisan route:clear: deletes the cached route file
  • php artisan view:clear: deletes compiled Blade views
  • php artisan event:clear: deletes cached events and listeners
  • php artisan optimize:clear: clears the caches above that were created by optimization
Code
php artisan optimize:clear
php artisan cache:clear
php artisan config:clear
php artisan route:clear
php artisan view:clear
php artisan event:clear

When should you clear each cache?

  • config: after changing .env or files in config/ when you previously ran config:cache
  • route: after adding or changing routes while route caching is on
  • view: when Blade changes do not appear
  • event: after changing event listener discovery
  • cache: when stale application data is returned from the cache store

Why does .env not update after a change?

When the configuration is cached, Laravel stops reading .env on each request. Your edits are ignored until you clear or rebuild the cache. Run:

Code
php artisan config:clear

In code, only call env() inside files in config/. Elsewhere use config(). Calls to env() outside config files return null once the config is cached.

How do you cache everything for production?

Production deploys usually rebuild the caches after clearing them.

Code
php artisan optimize:clear
php artisan optimize

optimize caches config, events, routes and views. You can also run config:cache, route:cache, view:cache and event:cache individually.

How do you clear caches from code?

Avoid exposing a public route for this. If you need it in a controlled place, such as an admin-only action or a deploy script, call Artisan.

CSS
use Illuminate\Support\Facades\Artisan;

Artisan::call('optimize:clear');

How do you clear a specific cache store or key?

CSS
php artisan cache:clear redis

# in code
Cache::forget('dashboard-stats');
Cache::store('redis')->flush();

Be careful with flush() on a shared Redis server. It can remove data used by other apps if they share the same store.

How do you verify it works?

  1. Change a value in .env and read it with php artisan tinker using config('app.name')
  2. If it still shows the old value, run php artisan config:clear and check again
  3. Run php artisan route:list after route changes to confirm the new routes appear

What are the common mistakes?

  • Running cache:clear and expecting config or route files to be removed
  • Clearing caches in production at peak traffic without rebuilding them afterwards
  • Using env() outside config files
  • Forgetting that the OPcache or PHP-FPM process may need a reload after a deploy

FAQ

What does php artisan optimize:clear do?

It removes the cached framework files created by optimize, such as config, route, view and event caches.

Does cache:clear delete session data?

It clears the default cache store. Sessions are only affected if they use the same store.

Is it safe to run these on production?

Yes, but the first requests after clearing are slower while Laravel rebuilds what it needs. Rebuild with php artisan optimize.

References

Article Index & Topic Tags
PerformanceLaravelCacheArtisan

YouTube Channel

Build Along With Me

Practical walkthroughs on Laravel, React, APIs and deployment workflows.

Muhammad Yasir Amin
Available for Contracts
Author & Solutions Architect

Senior Full Stack Engineer

Independent Senior Full Stack Engineer working on Laravel, React and Next.js applications, APIs and delivery workflows.

Laravel & PHP ApplicationsReact & Next.js InterfacesREST APIs & IntegrationsDatabase Queries & DebuggingDocker Development WorkflowsClear Scope & Handover
Discuss Your Next Step

What Does Your Application Need Next?

Share your current system, the problem you want to solve and what a useful result looks like. We can identify the right starting point and agree on a practical scope.

Technical Audit

Find the Next Useful Fix

Application Development

Scoped, Reviewable Milestones

Ongoing Support

Agreed Capacity and Priorities

Share your goals, current stack and requirements before the call.