Handle an incoming request.

@param  \Illuminate\Http\Request $request
@param  \Closure                 $next
@param null                      $permission
@return mixed
172009
public function handle($request, Closure $next, $permission = null)
    {
        if (! app('Illuminate\Contracts\Auth\Guard')->guest()) {
            if ($request->user()->can($permission)) {
                return $next($request);
            }

            return $request->ajax ? response('Forbidden.', 403) : redirect(route('login'));
        }
    }
1111493
public function handle($request, Closure $next, $role = null, $permission = null)
    {
        if (Auth::guest()) {
            return redirect('/admin/login');
        }

        if ($role && ! $request->user()->hasRole($role)) {
            throw new NotFoundHttpException;
        }

        if ($permission && ! $request->user()->can($permission)) {
            throw new NotFoundHttpException;
        }

        return $next($request);
    }
294154
public function handle($request, Closure $next, ?string $action = null)
    {
        if (! $this->authorize($action)) {
            return $this->responseOnUnauthorized($request);
        }

        return $next($request);
    }
662550
public function handle($request, Closure $next)
    {
        if ($request->user() != null && $request->user()->permissionCan($request)) {
            return $next($request);
        }

        abort(403);

        return false;
    }
200149
public function handle($request, Closure $next)
    {
        if (!$this->debugbar->isEnabled()) {
            abort(404);
        }

        return $next($request);

    }
1050465
public function handle(Request $request, Closure $next)
    {
        $response = $next($request);

        $headers = (new SecureHeaders(config('secure-headers', [])))->headers();

        foreach ($headers as $key => $value) {
            $response->headers->set($key, $value, true);
        }

        return $response;
    }
173226
public function handle($request, Closure $next, $permissions)
	{
		if (auth()->guest() || !$request->user()->can(explode('|', $permissions))) {
			abort(403);
		}
		return $next($request);
	}
801350
public function handle($request, Closure $next)
    {
        $this->attributes = array_slice(func_get_args(), 2);

        $this->clean($request);

        return $next($request);
    }
1202645
public function handle($request, Closure $next)
    {
        if ($this->cors->isPreflightRequest($request)) {
            return $this->cors->handlePreflightRequest($request);
        }

        return $next($request);
    }
995406
public function handle($request, Closure $next)
    {
        if ( ! $this->auth->check()) {
            return cms_api()->response('Unauthorized.', 401);
        }

        return $next($request);
    }
1194850
public function handle($request, Closure $next, $permissions = null, $any = false)
    {
        if (is_null($permissions)) {
            $permissions = $this->getPermissions($request);
            $anyPermission = $this->getAny($request);
        } else {
            $permissions = explode('|', $permissions); // Laravel 5.1 - Using parameters
            $anyPermission = $any;
        }

        if (is_null($this->user)) {
            return $this->forbiddenResponse();
        }

        if ($this->user->isSuperUser()) {
            return $next($request);
        }

        if (is_array($permissions) and count($permissions) > 0) {
            $canResult = true;

            foreach ($permissions as $permission) {
                $canPermission = $this->user->hasPermission($permission);

                // Check if any permission is enough
                if ($anyPermission and $canPermission) {
                    return $next($request);
                }

                $canResult = $canResult & $canPermission;
            }

            if (! $canResult) {
                return $this->forbiddenResponse();
            }
        }

        return $next($request);
    }
831772
public function handle($request, Closure $next, $permissions)
    {
        if (! empty($permissions) && $this->auth->check()) {
            $permissions = explode(':', $permissions);

            if ($this->permissionsHelper->can($permissions)) {
                return $next($request);
            }

            return abort(403);
        }
        if ($request->ajax()) {
            return response('Unauthorized.', 401);
        } else {
            return redirect()->guest('auth/login');
        }
    }
1009960
public function handle($request, Closure $next, string $permission = '')
    {
        if (!$this->getTokenPermissions($request->header('Hc-Token'))->hasTokenPermission($permission))
            return HCLog::error('APP-003', trans ("HCApps::apps_tokens.access_denied"));

        return $next($request);
    }
164308
public function handle(Request $request, Closure $next, $resource = null, $permission = null)
    {
        if ($this->auth->guest()) {
            if (!$this->acl->isAllowed('guest', $resource, $permission)) {
                return $this->notAllowed($request);
            }
        } elseif (!$this->acl->isAllowed($this->auth->user(), $resource, $permission)) {
            return $this->notAllowed($request);
        }

        return $next($request);
    }
1154688
public function handle($request, Closure $next, $model, $privilege = 'read')
    {
        Gate::authorize($privilege, app($model));
        
        return $next($request);
    }
552989
public function handle($request, Closure $next)
    {

        $request = $this->requestConverter->toCmsRequest($request);

        $request->provideCmsPath(function($request){
            $this->attachCmsPath($request);
        });

        $this->injectRequest($request);

        $this->app['events']->fire($this->requestEventName,[$request, $this]);

        return $next($request);

    }
1065721
public function handle($request, Closure $next)
    {
        if (auth()->check() && (auth()->user()->hasPermission('admin-api-access') || auth()->user()->isSuperAdmin())) {
            return $next($request);
        }
        return abort(404, 'Not Found');
    }