t0berius's avatar

laravel middleware only()

Is there a way I can use only in the middleware, when constructing the middleware as array?

Like:

public function __construct(){

    $this->middleware([
        'auth',
        'middleware1',
        'middleware2',
        'middleware3' => [
            'only' => [
                'getMethodName1',
                'getMethodName2',
            ]
        ],
    ]);
}

To assign middleware3 only to the specified methods.

0 likes
3 replies
ejdelmonico's avatar

You can specify only or except in the middleware constructor such as, $this->middleware('auth', ['only' => ['something']]);

t0berius's avatar

@ejdelmonico

I thought there might be a way to use the array syntax as I used above, using multiple $this->middleware() statements will work for sure.

MThomas's avatar

You can also specify it on a route group and let it cover all in the group.

Please or to participate in this conversation.