Laravel Eloquent pagination on relationships

前端 未结 3 706
梦如初夏
梦如初夏 2021-01-05 06:48

I am trying to paginate a Eloquent relationship like this:

 $query = Product::find(1)->options()->paginate();

But I get the following

3条回答
  •  不知归路
    2021-01-05 06:53

    Create a custom length-aware paginator.

    $options = new LengthAwarePaginator(Product::find(1)->options()->
                ->skip(($request->input('page', 1) - 1) * 10)->take(10)->get(),
                Product::find(1)->options()->count(), 
                10, $request->input('page', 1),
                [
                    // paginator options here
                ]);
    

提交回复
热议问题