I'm working on Laravel and try to make anACL
system. I have a Role Middleware From myController I've sent Role
to my RoleMiddleware two way.
first one is send string.
$this->middleware('HasRole:User|Admin|Author');
this way i'm get a string when use dd()
function.
and the second way is.
$this->middleware('HasRole:User,Admin,Author');
this way i'm get an array when use dd()
function.
but this array only contains a single value.
result like this.
array:1 [▼
0 => "User"
]
other two value Admin
& Author
doesn't appear in this array.
How can i work both way string & array
Here is my middleware.
public function handle($request, Closure $next,$role='')
{
$roles=is_array($role)? $role: explode('|', $role);
dd($roles);
if($request->user()===null)
{
return response('Insufficient Access',401);
}
if($request->user()->hasAnyRole($roles) || !$roles)
{
return $next($request);
}
return response('Insufficient Permission',401);
//return $next($request);
}