In the laravel docs they discuss eager loading related data to solve the N+1 query problem. I would like to filter my data based on the data from these relationships, without having to iterate through the results (that is, I would like this done at query time)
An example used in the docs is as follows:
$books = App\Book::with('author.contacts')->get();
If I wanted to filter these books to only include those who's author lives in the zip code 12345, how would I do that?
Neither of the following queries work for me:
$books = App\Book::with('author.contacts')->where('zip', 12345)->get();
$books = App\Book::with('author.contacts')->where('author.contacts.zip', 12345)->get();
Is there a simple way to do this in Eloquent?
from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2aH9src
via IFTTT
Aucun commentaire:
Enregistrer un commentaire