// if $id has value it will include "where('id','<',$id) else will return all"
$wells = DB::table('well_s')
->when($id, function ($query, $id) {
return $query->where('id','<',$id);
})
->paginate(20);
//make sure that all your queries/builder has ->paginate and not a ->get() or
//->first() then do {{ $var->links() }} in the blade
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]);
}