What do you mean by 'It doesn't work at all.'? Do you get any errors? Or just a huge amount of queries?
Eager loading
Hi,
I'm new in Laravel (5) and i have a little question. First, i have 3 tables (with SoftDeletes and Timestamps columns ) : Users with primary id : uid Pages with primary id : pid Relation with primary id : 'uid - pid'
Classical indeed. I would like to be able to retrieve all Pages which have a relation and relative to a User and in one "query".
Pages::with('owner')->where('uid', '=', $uid);
It doesn't work at all. I think it easy but i can't find the solution :(
Bye !
You want all the pages from an user ??
$user = User::finsOrFail($uid);
$pages = $user->pages;
Don't worry about one or two queries. Even eager loading would make two queries. With eloquent you should expect at least one query per relationship it is the way it works.
By the way I see you have a Pages model, it should be singular, Page, it is the convention.
Please or to participate in this conversation.