How do I filter a relation with attribute from model?

Viewed 136

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?

0 Answers
Related