#Resource route does not take middleware into account

3 messages · Page 1 of 1 (latest)

abstract rapids
#

I was working on a route that is part of a resource route. I wanted to add no-cache policy so that the page has to be fully reloaded everytime and was surprised to see that the no-cache policy was not taken into account.

Here is my route:

Route::resource('event', 'EventController')->middleware('no-cache');

And here is the content of my no-cache middleware:

public function handle(Request $request, Closure $next)
{
    $response = $next($request);

    return $response->header('Cache-Control', 'no-store, no-cache, must-revalidate, max-age=0')
        ->header('Pragma', 'no-cache')
        ->header('Expires', '0');
}

When browsing to /event/1/edit, the middleware is not applied.

It works fine when I have the get route in my web.php routes file:

Route::get('event/{id}/edit', 'EventController@edit')->middleware('no-cache');

Did I miss something in the documentation?

vernal shale
abstract rapids
#

I fail to see how that is related to my issue, as the documentation part you link to says which may be used; which implies that it is not loaded by default.

I have the origin of the issue: I had the same resource route defined later in the routes file so that one was taken into account.

When I removed the redundant route, the no-cache middleware is applied properly