I wonder if I can do this in Laravel Route. Let's say I have Admin
, Premium
and User
(which can be login too by using Auth
) Middleware. Also, I have controller with methods like this: index
, create
, edit
, delete
and I want Admin
to be able do all those things, but Premium
can only be able to access index
method, and User
can't access anything in this controller (he can access another controller). I know I can use except
or only
middleware method like this:
public function __construct()
{
$this->middleware('premium')->only('index');
$this->middleware('admin');
// or maybe $this->middleware('admin')->except('index');
}
but when I try to put these two middlewares in __construct
method they will start to conflict each other, it makes sense because index method can be access by Premium Member
but then can't be access by the Admin
itself. Btw my middleware is simply checking:
if (Auth::check()) {
if (Auth::user()->role == 'Admin') {
return $next($request);
}
}
return redirect('/home');
So, back to my question, can I have OR Middleware so I can avoid conflict from multiple middleware (which is must be AND condition when they written at the same controller constructor)?
Thanks a lot.