'How do I filter a relation with attribute from model?
I have a very complex database model in Laravel 9. I would like to get "relations" with a custom query. Currently I do this via computed properties, but these cannot be eager loaded.
Here is a simplified example:
public function playlist()
{
$fairuse = $this->show_only_fairuse;
return Playlist::with(['songs' => function ($q) use ($fairuse) {
$q->where('fairuse', $fairuse);
}])->get();
}
Does anyone have any ideas on how to eager load this?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
