Home > Mobile >  How to use Laravel paginator?
How to use Laravel paginator?

Time:10-31

I want to export query results to pagination. And the pagination should have the following data results per page, column names, offset.

I tried this code

$customer = Customer::where("customer_id", $request->customer_id)->first();
$customer->paginate($request->limit, ['*'], $request->offset)->toArray();

But this code returned me a full of customers, i dont want this. It ignores the where condition.

As i said before i want to pagination should have per page, column names(i now ['*'] is column names), offset and of course my query results.

CodePudding user response:

I don't think first() and toArray() functions are okay here. I would go for something like this:

$customer = Customer::where('customer_id', $request->customer_id)->paginate(
    $request->limit, ['*'], $request->offset
);
  • Related