Handle an incoming request.

@param \Illuminate\Http\Request $request
@param \Closure                 $next

@return \Illuminate\Http\RedirectResponse|mixed
353550
public function handle(Request $request, Closure $next)
    {
        $action = $this->container->make('router')->current()->getAction();

        if (array_key_exists('group', $action)) {
            $action['groups'] = $action['group'];
        }
        if (array_key_exists('role', $action)) {
            $action['roles'] = $action['role'];
        }
        if (array_key_exists('permission', $action)) {
            $action['permissions'] = $action['permission'];
        }

        // Check user access only if least one role or permission is added to current route
        if (array_key_exists('roles', $action) || array_key_exists('permissions', $action)) {
            $url      = $this->container->make('url');
            $config   = $this->container->make('config');
            $redirect = $this->container->make('redirect');

            // If user is not authenticated redirect to login route
            if (!$this->keeper->check()) {
                return $redirect->guest($url->route($config->get('vi-kon.auth.login.route')));
            }

            // Get roles and permissions
            $groups      = Arr::get($action, 'groups', []);
            $roles       = Arr::get($action, 'roles', []);
            $permissions = Arr::get($action, 'permissions', []);

            /** @noinspection ArrayCastingEquivalentInspection */
            if (!is_array($groups)) {
                $groups = [$groups];
            }
            /** @noinspection ArrayCastingEquivalentInspection */
            if (!is_array($roles)) {
                $roles = [$roles];
            }
            /** @noinspection ArrayCastingEquivalentInspection */
            if (!is_array($permissions)) {
                $permissions = [$permissions];
            }

            // If user is authenticated but has no permission to access given route then redirect to 403 route
            if ($this->keeper->hasGroups($groups) !== true ||
                $this->keeper->hasRoles($roles) !== true ||
                $this->keeper->hasPermissions($permissions) !== true
            ) {
                $router = $this->container->make('router');
                $log    = $this->container->make('log');

                $currentRoute = $router->current();

                $log->notice('User has no access to page', [
                    'user'        => $this->keeper->user()->toArray(),
                    'permissions' => $permissions,
                    'roles'       => $roles,
                    'groups'      => $groups,
                    'route'       => $currentRoute->getName(),
                ]);

                throw new AccessDeniedHttpException();
            }
        }

        return $next($request);
    }
1164382
public function handle($request, Closure $next)
    {
        if (! AuthRagnarok::check()) {
            if ($request->ajax()) {
                return response('Unauthorized.', 401);
            } else {
                return redirect()->guest('/auth/login');
            }
        }

        return $next($request);
    }
217595
public function handle($request, Closure $next)
    {
        $this->app->setLocale($this->getCurrentLocale($request));

        return $next($request);
    }
1082528
public function handle($request, Closure $next)
    {
        $this->aclPolicy->defineAbilities();

        if ( ! $this->aclPolicy->passesAuthorization() ) {
            abort(403, config('acl.unauthorized_message'));
        }

        return $next($request);
    }
1200087
public function handle($request, Closure $next)
    {
        if ($this->auth->check()) {
            /** @var CoreInterface $core */
            $core = app(Component::CORE);

            return redirect()->route( $core->prefixRoute(NamedRoute::HOME) );
        }

        return $next($request);
    }
336130
public function handle($request, Closure $next)
    {
        if ($request->has('locale')) {
            $selectedLocale = $request->get('locale');
            $request->session()->put('locale', $selectedLocale);

            app()->setLocale($selectedLocale);

            return redirect()->to($request->getPathInfo());
        } elseif (session()->has('locale')) {
            $selectedLocale = session('locale');
            app()->setLocale($selectedLocale);
        }

        return $next($request);
    }
890253
public function handle(Request $request, Closure $next)
    {
        if (!$this->service->isCorsRequest($request)) {
            return $next($request);
        }

        if ($this->service->isPreflightRequest($request)) {
            return $this->service->handlePreflightRequest($request);
        }

        return $this->service->handleRequest($request, $next($request));
    }
805307
public function handle($request, Closure $next)
    {
        if( auth()->check() ) {
            $user = auth()->user();
            $user->updateLastActivity();
        }

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

        return $next($request);
    }
464288
public function handle(Request $request, Closure $next)
    {
        // If the request URL is ignored from localization.
        if ($this->shouldIgnore($request)) return $next($request);

        $this->localization->setRouteNameFromRequest($request);

        return $next($request);
    }
285554
public function handle($request, Closure $next)
    {
        $route = $this->router->getCurrentRoute();

        if (! $this->auth->check(false)) {
            $this->auth->authenticate($route->getAuthenticationProviders());
        }

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

		foreach ( $this->cookies->getQueuedCookies() as $cookie )
			$response->headers->setCookie( $cookie );

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

        if ($request->session()->has('language')) {
            $local = $request->session()->get('language', config('app.locale'));
            app()->setLocale($local);
        }

        return $next($request);
    }
482879
public function handle($request, Closure $next)
    {
        if (auth()->guest() || !user()->hasRoles(['client', 'member'])) {
            return $next($request);
        }
        $this->beforeSendingThroughPipeline();
        $response = $next($request);
        $this->afterSendingThroughPipeline();

        return $response;
    }
1301372
public function handle($request, Closure $next)
    {
        if ( ! $this->auth->check()) {

            if ($request->ajax() || $request->wantsJson()) {
                return response('Unauthorized.', 401);
            } else {
                /** @var CoreInterface $core */
                $core = app(Component::CORE);

                return redirect()->route( $core->prefixRoute(NamedRoute::AUTH_LOGIN) );
            }
        }

        return $next($request);
    }
855416
public function handle($request, \Closure $next)
    {
        $this->filter->add(
            'body_class',
            $this->dispatchBodyClass($request->route())
        );

        return $next($request);
    }
1218707
public function handle($request, Closure $next)
    {
        if (! in_array($this->auth->user()->role->id, $this->allowed_roles)) {
            return redirect()->route('admin.dashboard');
        }

        return $next($request);
    }