elliotk
124
2
Laravel

Paginate Eager Loaded Relationship

Posted 7 months ago by elliotk

Hello,

I am trying to get pagination working for Products here. Where I have the paginate(6) at the moment, the correct number of Products are returned, although I don't know if it's the correct place to put it.

However, I have tried all sorts to get the links() to show in blade, and I can't figure it out.

Is there a special way with Eager Loaded relations?

class CategoryController extends Controller
{
    public function view(Category $category)
    {
        $category->load(['products' => function ($products) {
            $products->enabled()->with('media')->paginate(6);
        }])->with('media');

        return view('shop.category.index', compact('category'));
    }
}

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.