/** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index(Request $request) { if ($request->has('search')) { $posts = Post::where('id', 'LIKE', "%" . $request->input('search') . "%")->orWhere('title', 'LIKE', "%" . $request->input('search') . "%")->paginate(5); } else { if ($request->has('sortby')) { $posts = Post::orderBy($request->input('sortby'))->paginate(5); } else { $posts = Post::paginate(5); } } $posts->setPath(url() . '/back/post'); return view('pages.admin.post.list', ['posts' => $posts]); }