Answer the question
In order to leave comments, you need to log in
How to restrict access by route?
In a laravel project, I decided to use the bouncer package to manage user roles,
I did everything according to the example from the documentation, but still, not only admins, but also ordinary users go through the route, how to properly configure access via routes using bouncer?
Answer the question
In order to leave comments, you need to log in
With Middleware. Here, for example, is how it is implemented for me. I am using laravel-permissions
class AdminMiddleware
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
$user = User::all()->count();
if (!($user == 1)) {
if (!Auth::user()->hasPermissionTo('Administer roles & permissions')) //если у пользователя нет таких прав
{
abort('401');
}
}
return $next($request);
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question