Answer the question
In order to leave comments, you need to log in
How to skip some number of rows in a selection in Laravel?
The selection goes through many filters, as a result we get a filtered and sorted $users.
And you just need to skip a certain number of first lines (number * page) and select the next few lines, i.e. this is custom pagination.
And then I ran into a problem: the limit(6)
and methods take(6)
work fine on $users
, but offset(2)
they skip(2)
give an error that such methods do not exist.
What to do in such a situation?
Why don't the methods described in the docs and suggested (and marked with solutions) in similar questions about pagination work?
The code:
public function getUsers (Request $request) {
if ( $request->drivecats ) {
$drivecats = explode(',', $request->drivecats);
$users_id = DrivecatUser::whereIn('drivecat_id', $drivecats)->with('drivecats')->pluck('user_id');
$users = User::whereIn('id', $users_id)->get();
} else {
$users = User::has('drivecats')->get();
}
$users = $users->skip(1)->take(6);
return view('pages.users', ['users' => $users]);
}
Method skip does not exist.
Method offset does not exist.
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question