Reputation: 9201
I'm using Laravel 4 to get all the persons that have a score for a certain event
This is the query i'm using
$event = Person::with(array('eventscore' => function($q){
$q->where('id', 3);
}))->get();
This is the output
Is there any way that i can return only the persons that have a score? Thanks!
Upvotes: 0
Views: 74
Reputation: 33058
with()
will not limit the Person
s returned, it will only limit eventscores
. If you want only Person
s that have an event score, you use has
or whereHas
.
$event = Person::whereHas('eventscore', function($q) {
$q->where('id', 3);
})->get();
Upvotes: 2