In my Property Model I have these two relationships defined
public function images() {
return $this->hasMany('Image')
->where('approved', '=', 1);
}
public function pending_images() {
return $this->hasMany('Image')
->where('approved', '=', 0);
}
In my Controller, I create a Property object and try to fetch both the approved and pending images.
$images = $property->images;
$pending = $property->pending_images;
var_dump($images);
var_dump($pending);
exit;
The $images variable is a Illuminate\Database\Eloquent\Collection as expected.
However, $pending is just NULL!
I try fetching the last DB query, using this answer, and it seems that the pending query is not even being executed. (The last query run has approved = 1, which is for the images relationship.)
My suspicion is that it might be a problem that the relationship is on the same table but I'm stumped.