Handle an incoming request.

@param  \Illuminate\Http\Request  $request
@param  \Closure  $next
@return mixed
340673
public function handle($request, Closure $next)
    {
        $route = $this->router->current()->methods()[0] . ' /' . $this->router->current()->uri();

        $isPermissionAllRoutes = RoutePermissionModel::getRoutePermissionsRoles('*');
        if ($isPermissionAllRoutes) {
            if (($user = $this->user($request)) === 401) {
                return response()->json(null, 401);
            }

            $hasRole  = $user->hasRole($isPermissionAllRoutes->roles, false);
            $hasPerms = $user->can($isPermissionAllRoutes->permissions, false);

            $hasRolePerm = $hasRole || $hasPerms || (is_array($isPermissionAllRoutes->roles) && in_array('@', $isPermissionAllRoutes->roles));

            if (!$hasRolePerm) {
                return response()->json(null, 403);
            }
        }

        $routePermission = RoutePermissionModel::getRoutePermissionsRoles($route);
        if ($routePermission) {
            if (($user = $this->user($request)) === 401) {
                return response()->json(null, 401);
            }

            $hasRole  = $user->hasRole($routePermission->roles, false);
            $hasPerms = $user->can($routePermission->permissions, false);

            $hasRolePerm = $hasRole || $hasPerms || (is_array($routePermission->roles) && in_array('@', $routePermission->roles));

            if (!$hasRolePerm) {
                return response()->json(null, 403);
            }
        }

        return $next($request);
    }
280947
public function handle( $request, Closure $next )
    {
        if( !$this->sentinel->check() )
        {
            return $this->denied( $request );
        }

        return $next( $request );
    }
653223
public function handle($request, \Closure $next)
    {
        if ($this->auth->check()) {
            return Redirect::route(config('society.user.config.redirect_route_after_login'));
        }

        return $next($request);
    }
329398
public function handle($request, Closure $next)
    {
        try {
            $response = $next($request);
        } catch (Exception $e) {
            $response = $this->handleException($request, $e);
        }

        if ($this->sentMail() && $response instanceof Response) {
            $this->appendToResponse($response);
        }

        return $response;
    }
676365
public function handle(Request $request, Closure $next)
    {
        if ($request->ajax() || $request->wantsJson()) {
            return $next($request);
        }

        return response('Method not allowed', 405);
    }
987842
public function handle(Request $request, Closure $next)
    {
        $request::setTrustedProxies([], $this->getTrustedHeaderNames()); // Reset trusted proxies between requests
        $this->setTrustedProxyIpAddresses($request);

        return $next($request);
    }
52718
public function handle($request, Closure $next)
    {
        $response = $next($request);

        if ($response instanceof Response) {
            $response->isNotModified($request);
        }

        return $response;
    }
1119153
public function handle(Request $request, Closure $next)
    {
        $request = $this->processRequest($request);
        return $next($request);
    }
1196279
public function handle($request, Closure $next)
    {
        if ($request->method() != 'GET') {

            /** @var \Approached\LaravelImageOptimizer\ImageOptimizer $imageOptimizer */
            $imageOptimizer = app('Approached\LaravelImageOptimizer\ImageOptimizer');

            foreach ($request->allFiles() as $one) {
                if (is_array($one)) {
                    foreach ($one as $file) {
                        if ($this->isImageFile($file)) {
                            $imageOptimizer->optimizeUploadedImageFile($file);
                        }
                    }
                } else {
                    if ($this->isImageFile($one)) {
                        $imageOptimizer->optimizeUploadedImageFile($one);
                    }
                }
            }
        }

        return $next($request);
    }
234989
public function handle($request, Closure $next)
    {
        $response = $next($request);

        if (!in_array($response->getStatusCode(), config('maxfactor-support.enforceDomainsStatusCodes'))) {
            return $response;
        }

        return $this->validDomain($request, $response);
    }
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');
    }
729100
public function handle($request, Closure $next)
    {
        if ($request->has('include')) {
            $this->service->parseIncludes($request->get('include'));
        }

        return $next($request);
    }
536806
public function handle($request, Closure $next)
    {
        $response = $next($request);

        if (! $response->headers->has('Etag')) {
            $response->setEtag(md5($response->getContent()));
        }

        $response->isNotModified($request);

        return $response;
    }
635269
public function handle(Request $request, Closure $next)
    {
        /** @var Response $response */
        $response = $next($request);

        if ($this->stack->count() > 0) {
            $dumped = \implode(\PHP_EOL, $this->stack->all());

            $this->stack->clear();

            $response->setContent($dumped . $response->getContent());
        }

        return $response;
    }
953052
public function handle($request, Closure $next)
    {
        $locale = \LocaleHelper::getLocale();
        app()->setLocale($locale);

        return $next($request);
    }
1306936
public function handle($request, Closure $next)
    {
        if ($this->auth->parser()->setRequest($request)->hasToken()) {
            try {
                $this->auth->parseToken()->authenticate();
            } catch (Exception $e) {
                //
            }
        }

        return $next($request);
    }
873539
public function handle(Request $request, \Closure $next)
	{
		$this->buildRepository($request);

		return $next($request);
	}