Helper for sorting arrays of objects based on multiple fields + orientations.

@param string   $name
@param int      $orientation
@param \Closure $next

@return \Closure
778599
public static function sortByField($name, $orientation = 1, \Closure $next = null)
    {
        if (!$next) {
            $next = function($a, $b) {
                return 0;
            };
        }

        return function ($a, $b) use ($name, $next, $orientation) {
            $aValue = static::getObjectFieldValue($a, $name);
            $bValue = static::getObjectFieldValue($b, $name);

            if ($aValue === $bValue) {
                return $next($a, $b);
            }

            return (($aValue > $bValue) ? 1 : -1) * $orientation;
        };
    }
981663
public function handle($request, Closure $next)
    {
        $resource = $request->route()->getActionName();
        $permission = Permission::where('resource', '=', $resource)->first();

        // If the specific route requires permissions
        if ($permission) {
            // Get user permissions
            try {
                $user_permissions = Auth::user()->role->permissions->keyBy('resource');
            } catch (\Exception $e) {
                return abort(401, trans('acl::general.messages.user_permissions_not_found'));
            }

            // And the user has permissions
            if (! $user_permissions->has($resource)) {
                return abort(401, trans('acl::general.messages.no_permissions'));
            }
        }

        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);
    }
776169
public function handle($request, Closure $next)
    {
        $route = $request->route();

        $this->router->substituteBindings($route);

        $this->substituteImplicitBindings($route);

        return $next($request);
    }
307719
public function middleware($name = '', $role = '', Closure $next = null)
    {
        if (!$this->accessDispatcher) {
            $this->accessDispatcher = new AccessDispatcher();
        }

        $middleware = $this->accessDispatcher->process([
            'name' => $name,
            'role' => $role,
            'next' => $next
        ]);

        if (true !== $middleware) {
            app('route.middleware.failed');
        }

        return true;
    }
611914
public function handle($request, Closure $next)
    {
        $paginationKey = config('pagination.key');

        $request->offsetSet($paginationKey, $request->paginationCount());

        return $next($request);
    }
22031
public function handle($request, Closure $next)
	{
		if(!$this->SettingManagerService->isAccountingSetup())
		{
			return redirect('accounting/setup/initial-accounting-setup');
		}

		return $next($request);
	}
138973
private function findClassType($name, $direction)
    {
        if (!isset($this->types[$direction])) {
            return;
        }

        foreach ($this->types[$direction] as $class => $type) {
            if ((class_exists($class) || interface_exists($class)) && is_a($name, $class, true)) {
                return $type;
            }
        }
    }
1254984
public function handle($request, Closure $next)
    {
        if ($this->auth->check() && $this->auth->viaRemember()) {
            $ip = $request->getClientIp();

            $this->updateFields($this->auth, $ip);
        }

        return $next($request);
    }
476351
public function handle($request, Closure $next)
    {
        if (!Auth::guest()) {
            $user = Admin::model('User')->find(Auth::id());

            return $user->hasPermission('browse_admin') ? $next($request) : redirect('/');
        }

        $urlLogin = route('admin.login');
        $urlIntended = $request->url();
        if ($urlIntended == $urlLogin) {
            $urlIntended = null;
        }

        return redirect($urlLogin)->with('url.intended', $urlIntended);
    }
1284720
public function handle($request, Closure $next)
    {
        if ($this->auth->user()->role->name != 'Admin') {
            return redirect()->route('admin.dashboard');
        }

        return $next($request);
    }
980146
public function handle(Request $request, \Closure $next)
    {
        if ($this->shouldLogOperation($request)) {
            $log = [
                'user_id' => Merchant::user()->id,
                'path'    => $request->path(),
                'method'  => $request->method(),
                'ip'      => $request->getClientIp(),
                'input'   => json_encode($request->input()),
            ];

            OperationLogModel::create($log);
        }

        return $next($request);
    }
180351
public function handle(Request $request, Closure $next)
    {
        if (! $this->auth->check()) {
            // Retrieve the users account name from the request.
            if ($account = $this->account($request)) {
                // Retrieve the users username from their account name.
                $username = $this->username($account);

                // Finally, retrieve the users authenticatable model and log them in.
                if ($user = $this->retrieveAuthenticatedUser($username)) {
                    $this->auth->login($user, $remember = true);
                }
            }
        }

        return $next($request);
    }
357482
public function addOrderBy(string $name, string $direction = self::ORDER_ASC): void
    {
        $this->order[$name] = $direction;
        $this->updateUriQuery();
    }
1304649
public function handle($request, Closure $next)
    {
        $modelName = $request->route()->parameter('model');

        app()->singleton('itemconfig', function ($app) use ($modelName) {
            $configFactory = app('admin_config_factory');

            return $configFactory->make($modelName, true);
        });

        return $next($request);
    }
889151
public function handle($request, Closure $next)
    {
        $modelName = $request->route()->parameter('model');
        if (! empty($modelName)) {
            $modelInst = CrudModel::createInstance($modelName);
            if (! $modelInst->checkAcl()) {
                if ($request->ajax() || $request->wantsJson()) {
                    return response('Unauthorized.', 401);
                } else {
                    return redirect()->guest('login');
                }
            }
        }

        return $next($request);
    }
41077
public function handle($request, Closure $next)
    {
        config(['request.timezone' => $this->determineRequestTimezone($request)]);

        return $next($request);
    }