middleware( function ($request, $next) { app('view')->share('title', (string)trans('firefly.currencies')); app('view')->share('mainTitleIcon', 'fa-usd'); $this->repository = app(CurrencyRepositoryInterface::class); $this->userRepository = app(UserRepositoryInterface::class); return $next($request); } ); } /** * Show overview of currencies. * * @param Request $request * * @return Factory|View * @throws ContainerExceptionInterface * @throws NotFoundExceptionInterface */ public function index(Request $request) { /** @var User $user */ $user = auth()->user(); $page = 0 === (int)$request->get('page') ? 1 : (int)$request->get('page'); $pageSize = (int)app('preferences')->get('listPageSize', 50)->data; $collection = $this->repository->getAll(); $total = $collection->count(); $collection = $collection->slice(($page - 1) * $pageSize, $pageSize); // order so default is on top: $collection = $collection->sortBy( function (TransactionCurrency $currency) { $default = true === $currency->userDefault ? 0 : 1; $enabled = true === $currency->userEnabled ? 0 : 1; return sprintf('%s-%s-%s', $default, $enabled, $currency->code); } ); $currencies = new LengthAwarePaginator($collection, $total, $pageSize, $page); $currencies->setPath(route('currencies.index')); $isOwner = true; if (!$this->userRepository->hasRole($user, 'owner')) { $request->session()->flash('info', (string)trans('firefly.ask_site_owner', ['owner' => config('firefly.site_owner')])); $isOwner = false; } return view('currencies.index', compact('currencies', 'isOwner')); } }