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 withCache::put())php artisan config:clear: deletes the cached configuration filephp artisan route:clear: deletes the cached route filephp artisan view:clear: deletes compiled Blade viewsphp artisan event:clear: deletes cached events and listenersphp artisan optimize:clear: clears the caches above that were created by optimization
php artisan optimize:clear
php artisan cache:clear
php artisan config:clear
php artisan route:clear
php artisan view:clear
php artisan event:clearWhen should you clear each cache?
- config: after changing
.envor files inconfig/when you previously ranconfig: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:
php artisan config:clearIn 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.
php artisan optimize:clear
php artisan optimizeoptimize 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.
use Illuminate\Support\Facades\Artisan;
Artisan::call('optimize:clear');How do you clear a specific cache store or key?
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?
- Change a value in
.envand read it withphp artisan tinkerusingconfig('app.name') - If it still shows the old value, run
php artisan config:clearand check again - Run
php artisan route:listafter route changes to confirm the new routes appear
What are the common mistakes?
- Running
cache:clearand 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.



