I created a filter for db table, but filtration just work for first page
I try this code in controller
public function index(Request $request)
{
$user=User::orderBy('created_at', 'ASC');
if($request->get('search'))
{
if ($request->get('type')) {
$user->where('type', $request->get('type'));
}
if ($request->get('id')) {
$user->where('id', (integer)$request->get('id'));
}
if ($request->get('first_name')) {
$user->where('first_name', $request->get('first_name'));
}
if ($request->get('email')) {
$user->where('email', $request->get('email'));
}
}
$users = $user->paginate(20);
$user->appends(['search' => $request->get('search')]);
return view('admin.user.index', compact('users'));
}
But I get this error
Call to undefined method Illuminate\Database\Query\Builder::appends()
How I can fix this error or how I can make filter works with all pages ?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire