Is there a way to reference the base model i'm query against? $person doesn't exist yet because i'm defining it but I want to eager load constraint the contacts returned based on the person's primary department. How do I reference the instance of the person model?
Route::get('/test', function() {
return $person = Person::with(['contacts' => function($q) use ($person) {
$q->where('parent_entities_id', $person->parent_entities_id);
}])->findOrFail(1);
});
Why can't you just create a new relationship method in your Person model ? Like :
public function parent(){
return $this->belongsTo('Person', 'parent_entities_id');
}
And then just call:
return $person = Person::with('parent')->findOrFail(1);
Will it do the trick or maybe I am missunderstanding something ?
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community