Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

domioanna's avatar

Struggling with Route::resource() and 'auth' Middleware

Is it just me who can't seem to assign the 'auth' middleware to a Route::resource()?

It doesn't seem to want to work when I assign the 'auth' middleware directly into __construct of the Controller either.

Can someone copy / paste working code for the above?

0 likes
4 replies
akael's avatar

Here is a working example for Controller middleware:

use Illuminate\Routing\Controller;

class AwesomeController extends Controller {

    public function __construct()
    {
        $this->middleware('csrf');
        $this->middleware('auth', ['only' => 'update'])
    }

}

You might checkout this blog post to read more: http://mattstauffer.co/blog/laravel-5.0-middleware-filter-style

2 likes
pmall's avatar

@domioanna

Is it just me who can't seem to assign the 'auth' middleware to a Route::resource()?

$router->group(['middleware' => 'your.middleware'], function($router)
{
  $router->resource('resource', 'resourceController');
});

Please or to participate in this conversation.