Pagination with findorfail
hey guys,
i'm trying to paginate a products of specific category route.
$category = Category::with('products')->findOrFail($id)->paginate(12);
but it gives me that error
Undefined property: Illuminate\Pagination\LengthAwarePaginator::$category
how to solve this please?
What do you think you are paginating exactly?
i'm getting a products of specific category but i cant paginate in this products
This is as efficient as eager-loading.
$category = Category::findOrFail($id)
$products = $category->products()->paginate(12);
@motazdev findOrFail returns a single model instance. So how are you intending to “paginate” a single model?
ohh okay i understand. thanks
Find $category first, then attach and paginate.
please can you give me any example? cause i think i'm doing what you told me
Please or to participate in this conversation.