public function handle(Request $request, Closure $next, $roles)
    {
        $accessDenied = true;

        if (!$user = $this->auth->getActiveUser()) {
            Flash::error(trans('dashboard::dashboard.flash.access_denied'));

            return redirect()->route('auth.login');
        }

        if (!is_array($roles)) {
            $roles = [$roles];
        }

        foreach ($roles as $role) {

            if (!$role = $this->role->getBySlug($role)) {
                continue;
            }

            if ($user->inRole($role)) {
                $accessDenied = false;
            }
        }

        if ($accessDenied) {
            Flash::error(trans('dashboard::dashboard.flash.access_denied'));

            // Redirect back to the previous page where request was made.
            return redirect()->back();
        }

        return $next($request);
    }
public function handle(Request $request, Closure $next, $roles)
    {
        $accessDenied = true;

        if (!$user = $this->auth->getActiveUser()) {
            Flash::error(trans('dashboard::dashboard.flash.access_denied'));

            return redirect()->route('auth.login');
        }

        if (!is_array($roles)) {
            $roles = [$roles];
        }

        foreach ($roles as $role) {

            if (!$role = $this->role->getBySlug($role)) {
                continue;
            }

            if ($user->inRole($role)) {
                $accessDenied = false;
            }
        }

        if ($accessDenied) {
            Flash::error(trans('dashboard::dashboard.flash.access_denied'));

            // Redirect back to the previous page where request was made.
            return redirect()->back();
        }

        return $next($request);
    }
public function handle ( Request $ request , Closure $ next , $ roles ) { $ accessDenied = true ; if ( ! $ user = $ this -> auth -> getActiveUser ( ) ) { Flash :: error ( trans ( 'dashboard::dashboard.flash.access_denied' ) ) ; return redirect ( ) -> route ( 'auth.login' ) ; } if ( ! is_array ( $ roles ) ) { $ roles = [ $ roles ] ; } foreach ( $ roles as $ role ) { if ( ! $ role = $ this -> role -> getBySlug ( $ role ) ) { continue ; } if ( $ user -> inRole ( $ role ) ) { $ accessDenied = false ; } } if ( $ accessDenied ) { Flash :: error ( trans ( 'dashboard::dashboard.flash.access_denied' ) ) ; // Redirect back to the previous page where request was made. return redirect ( ) -> back ( ) ; } return $ next ( $ request ) ; }
Check if user belongs to the specified role.

@param Request      $request
@param Closure      $next
@param string|array $roles

@return \Illuminate\Http\RedirectResponse
Check if user belongs to the specified role .