Mikegk
2 months ago

Relationship Problem

Posted 2 months ago by Mikegk

Hi guys,

I just faced a relationship problem.

I have got a "Category" Model that has many CategoryData (entries). One CategoryData belongs to the Category Model and it also belongs to a User.

The question is, how can I make sure, that only CategoryData with active users (user.status = 1) will be returned?

That's my try

$categories = Category::where(['status' => 1])
            ->with(['categoryData' => function ($q) {
                return $q->where(['status' => 1, 'kind' => 'header'])
                    ->limit(1);
            }, 'categoryData.user' => function ($q) {
                return $q->where(['status' => 1]);
            }])
            ->get();

...but that doesn't really work.

I would by glad for any ideas.

Please sign in or create an account to participate in this conversation.