13

I've cached my Laravel 5 routes by doing php artisan route:cache. This went succesfull for quite a while and when I changed a route is could cache them again and it would all work like it should.

The problem is that I've moved some routes to another route group and it seems that they won't be cached for some reason.

I've tried to cache them again but it didn't work. I've also tried php artisan cache:clear but still not working.

Routes.php changes:

Route::group(['prefix' => 'api', 'middleware' => 'auth'], function () {
   Route::get('invites', 'InvitationController@get');
   Route::get('invites/check', 'InvitationController@check');
});

Changed to:

Route::group(['prefix' => 'api'], function () {
   Route::post('auth', 'Auth\AuthController@authenticate');
   Route::get('invites', 'InvitationController@get');
   Route::get('invites/check', 'InvitationController@check');
});

As you can see I've moved those invitation routes to the Route group without the Authenticate Middleware. When I cached the routes again, it still does execute the Auth Middleware even when they are moved out of the group..

guidsen
  • 2,333
  • 6
  • 34
  • 55
  • 1
    Are you sure the caching is the problem? Also, show us your routes code – lukasgeiter Mar 28 '15 at 18:59
  • yes, see edit for routes. I tried a dd('test') in the Authentication Middleware and the route is this using the middleware even when it's not in the Route group anymore. – guidsen Mar 28 '15 at 19:05
  • Is it possible that the auth middleware is registered somewhere else as well? Possibly in the controller? To check if this is really a caching issue please change the URL of the route your testing. Like to `Route::get('invites2', ...`, cache it again and try to access the route. If you get a 404 it's not a caching problem. – lukasgeiter Mar 28 '15 at 19:08
  • Are there any routes before this? – Ohgodwhy Mar 28 '15 at 19:15
  • I've changed the `invites` to `invites2` and after the caching it show a `NotFoundHttpException`... Really strange. The middleware is registered as alias and not being used somewhere else in a Controller.. – guidsen Mar 28 '15 at 19:22

3 Answers3

30

The right syntaxe to remove cached route in laravel 5.* is

php artisan route:clear

Regards

Goopil
  • 301
  • 3
  • 3
  • 2
    And if you still have errors after that, you might want to run `php artisan route:cache` after that to load your updates. Stumped me for a few minutes! – Stan Smulders Oct 19 '17 at 09:35
  • 1
    For people with route update issues coming from Google: Try to [clear your browser's cache](https://superuser.com/a/304600/182460). – totymedli Apr 08 '19 at 03:07
  • thats funny , I had url variable `APP_URL` set to localhost in servers .env file. After correction it now runs ok. – CodeToLife Jun 26 '21 at 12:43
2

Try:

php artisan optimize

This will clear all the route cache as well as the file cache.

Joshua
  • 1,128
  • 3
  • 17
  • 31
MITHUN RAJ
  • 21
  • 2
1

If you don't want to optimize again with every change. You can try this;

CACHE_DRIVER=file to change => CACHE_DRIVER=array

After, you should clear to folder "bootstrap/cache"

I hope it works.

irfanyy
  • 49
  • 5