I'm trying to use paginate but it doesn't work, without paginate all are fine but when I use it I get this error Method Illuminate\Database\Eloquent\Collection::links does not exist
Controller:
$userorders=Userorder::where('user_id', $user_id)
->with('storeinfo')
->with('product')
->paginate(15)
->groupBy('order_number');
view:
@if( count($userorders) > 0 )
{!! $userorders->links() !!}
@endif
Because links()
is a method of LengthAwarePaginator
, instead groupBy
will return a Collection
, so the only way you can have your UserOrder grouped by its order_number is to switch the order of the calls, to this one
$builder= Userorder::where('user_id',$user_id)->with('storeinfo')->with('product');
$userOrdersPagination=$builder->paginate(15);
$userorders=$userOrdersPagination->groupBy('order_number')
And then you have to pass to the view also $userOrdersPagination
and use that to generate the links
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.