D
D
Denis Dormadekhin2018-02-09 15:42:43
Laravel
Denis Dormadekhin, 2018-02-09 15:42:43

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

1 answer(s)
E
Eugene, 2018-02-10
@Shelderr

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 question

Ask a Question

731 491 924 answers to any question