how to paginate search results laravel 8 code example
Example 1: laravel pagination with search filter
$wells = DB::table('well_s')
->when($id, function ($query, $id) {
return $query->where('id','<',$id);
})
->paginate(20);
Example 2: laravel search and return record with pagination
if(empty($request->search)){
$user = DB::table('users')->Paginate(15);
return view('/users', ['user' => $user]);
}else{
$user = DB::table('users')->where('name', 'like', '%'. $request->search .'%')->Paginate(15);
return view('/users', ['user' => $user]);
}