Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FEATURE REQUEST: Allow paginating when eager loading #15

Closed
abishekrsrikaanth opened this issue Jul 26, 2019 · 2 comments
Closed

FEATURE REQUEST: Allow paginating when eager loading #15

abishekrsrikaanth opened this issue Jul 26, 2019 · 2 comments

Comments

@abishekrsrikaanth
Copy link

So far loving this package. Very helpful.
Would it be possible to make use of the paginate function?

 $category = $this->getQuery()->with(['products' => function ($query)  {
            $query->paginate();
        }])->first();

What I am trying to do is show products within a category, but I want to paginate the products.
If this is out of the package's scope, can you suggest a good way to do this?
Not sure if this is a dumb question?

@staudenmeir
Copy link
Owner

Eager loading can't be used for pagination queries. Use lazy loading instead:

$category = $this->getQuery()->first();

$products = $category->products()->paginate();

If you want to access the products with $category->products:

$category->setRelation('products', $products);

@abishekrsrikaanth
Copy link
Author

@staudenmeir, sounds good. Appreciate it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants