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

Greedy download #705

Closed
eldarkhanov opened this issue Aug 5, 2017 · 5 comments
Closed

Greedy download #705

eldarkhanov opened this issue Aug 5, 2017 · 5 comments

Comments

@eldarkhanov
Copy link

Hi! How to implement a greedy download in medialibrary?

@freekmurze
Copy link
Member

What is a greedy download?

@eldarkhanov
Copy link
Author

I'm sorry, I meant Eager Loading... How to avoid multiple database requests?
In the controller, I get the data this way

return view('blog.index', ['posts', Blog::where('active', 1)->paginate(5)]);

Output in view

@foreach($posts as $post) <div class=""> <h3 class="">{{ $post->name }}</h3> <img src="{{ $post->getFirstMediaUrl('images') }}"> ... </div> @endforeach

All works, but it turns out a lot of queries to the database, please tell me how to avoid this

@sebastiandedeyne
Copy link
Member

You could add a with call to your query.

Blog::with('media')->where('active', 1)->paginate(5)

@eldarkhanov
Copy link
Author

Thanks already understood, earlier to make such it did not turn out, because I in the table did changes which are not necessary)

@eldarkhanov
Copy link
Author

Thanks to the author for the cool package

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

3 participants