/** * View the resources as a tabulated list. * @param \App\Http\Requests\GenericRequest $request * @return mixed */ public function index(GenericRequest $request) { if (!$this->user->isAdmin()) { return redirect()->route('resources.search'); } // Get the resources $resources = Resource::select('resources.*')->orderBy('title', 'ASC'); // Allow filtering by category or access $filter = $this->filter($request); if ($filter) { if (preg_match('/^category:(.*)$/', $filter, $matches)) { $resources = $resources->inCategory($matches[1]); } else { if (preg_match('/^access:(.*)$/', $filter, $matches)) { $resources = $matches[1] == 'null' ? $resources->whereNull('resources.access_id') : $resources->where('resources.access_id', $matches[1]); } } $resources = $resources->get(); } else { $resources = $resources->paginate(20); $this->checkPagination($resources); } // Render return View::make('resources.list')->with(['resources' => $resources, 'filter' => $filter]); }