82

This is regarding route cache on localhost

About Localhost

I have 2 routes in my route.php file. Both are working fine. No problem in that. I was learning route:clear and route:cache and found a small problem below.

if I comment any one route in my route.php file and then run below command

php artisan route:cache

This will keep the route disabled because the route list is in cache now. Now, go to route.php file and try to remove commented route and then try to run that enabled url. still it will show 404 because I need to remove cache by using below command

php artisan route:clear

So far everything is understood in localhost. No problem in that.

After deploying on shared hosting server on godaddy

Question : How can I remove the route cache on server?

miken32
  • 42,008
  • 16
  • 111
  • 154
Pankaj
  • 9,749
  • 32
  • 139
  • 283

7 Answers7

84

If you want to remove the routes cache on your server, remove this file:

bootstrap/cache/routes.php

And if you want to update it just run php artisan route:cache and upload the bootstrap/cache/routes.php to your server.

Dees Oomens
  • 4,554
  • 3
  • 29
  • 61
  • Can you tell why we should use route cache? I meant what's the problem if we don't use route cache? – Pankaj Jun 17 '16 at 11:10
  • 3
    @Helper There's no problem about not using route cache. It just can make "your route registration up to 100x faster" as noted in the [documentation](https://laravel.com/docs/5.2/controllers#route-caching). – Dees Oomens Jun 17 '16 at 13:21
49

If you are uploading your files through GIT from your local machine then you can use the same command you are using in your local machine while you are connected to your live server using BASH or something like.You can use this as like you use locally.

php artisan cache:clear

php artisan route:cache

It should work.

Sakil
  • 983
  • 1
  • 10
  • 18
39

For your case solution is :

php artisan cache:clear
php artisan route:cache

Optimizing Route Loading is a must on production :

If you are building a large application with many routes, you should make sure that you are running the route:cache Artisan command during your deployment process:

php artisan route:cache

This command reduces all of your route registrations into a single method call within a cached file, improving the performance of route registration when registering hundreds of routes.

Since this feature uses PHP serialization, you may only cache the routes for applications that exclusively use controller based routes. PHP is not able to serialize Closures.

Laravel 5 clear cache from route, view, config and all cache data from application

I would like to share my experience and solution. when i was working on my laravel e commerce website with gitlab. I was fetching one issue suddenly my view cache with error during development. i did try lot to refresh and something other but i can't see any more change in my view, but at last I did resolve my problem using laravel command so, let's see i added several command for clear cache from view, route, config etc.

Reoptimized class loader:

php artisan optimize

Clear Cache facade value:

php artisan cache:clear

Clear Route cache:

php artisan route:clear

Clear View cache:

php artisan view:clear

Clear Config cache:

php artisan config:clear
Amitesh Bharti
  • 14,264
  • 6
  • 62
  • 62
16

you can define a route in web.php

Route::get('/clear/route', 'ConfigController@clearRoute');

and make ConfigController.php like this

   class ConfigController extends Controller
{
    public function clearRoute()
    {
        \Artisan::call('route:clear');
    }
}

and go to that route on server example http://your-domain/clear/route

Bakhtiar
  • 661
  • 5
  • 18
  • 2
    Hmmmm genius.... and can you tell me how we can define this route to clear our cache when we can not clear our route cache? – Matthew Apr 26 '21 at 19:44
  • You can replace "route:clear" with all of these clear commands : "cache:clear" , "view:clear","config:cache" . – Bakhtiar Jul 12 '21 at 15:02
2

If you want to clear the route cache on the server, open the terminal provided by hosting providers (e.g., GoDaddy, NameCheap) and run these commands:

php artisan cache:clear
php artisan route:clear

if you're not able to find the terminal then you can create a route to clear the cache on the server:

<?php

use Illuminate\Support\Facades\Artisan;

Route::get('/clear-cache', function () {
   Artisan::call('cache:clear');
   Artisan::call('route:clear');

   return "Cache cleared successfully";
});

You can check this example

AHSEN ALEE
  • 29
  • 5
1

I recommend you to use php artisan optimize instead.

optimaze performs the following tasks:

  • Configuration cache successfully cleared.
  • Configuration cache successfully cached.
  • Routes cache successfully cleared.
  • Routes successfully cached.
  • Files successfully cached. Also, you have it in one command.
SEYED BABAK ASHRAFI
  • 4,093
  • 4
  • 22
  • 32
-1

Clear Cache On Shared Host Without Artisan Commands

How to Clear Route Cache from Browser

 Route::get('/route-cache', function() {
     $exitCode = Artisan::call('route:cache');
     return 'Routes cache cleared';
 });

How to Clear Config Cache from Browser

 Route::get('/config-cache', function() {
     $exitCode = Artisan::call('config:cache');
     return 'Config cache cleared';
 });

How to Clear Application Cache from Browser

 Route::get('/clear-cache', function() {
     $exitCode = Artisan::call('cache:clear');
     return 'Application cache cleared';
 });

How to Clear View Cache from Browser

 Route::get('/view-clear', function() {
     $exitCode = Artisan::call('view:clear');
     return 'View cache cleared';
 });
Rajib Bin Alam
  • 353
  • 1
  • 4
  • 16