How do I filter the eager loading results?

Posted 4 months ago by chrisgrim

Hi All,

I am trying to understand how to filter my eager loaded results. In my show method on my category controller I have

public function show(Category $category)
    {
         $category->load('events');
        
        return view('category.show', compact('category'));
    }

This returns my current category with the eager loaded events so my relationships are working. My question is how do I filter those returned events. I guess I should use a where() method but when I use

$category->load('events')->where('approved', Null)->get();

It is searching my categories class for the approved column, not my events class. Is there a way to tell Laravel to search the eager loaded class?

Thanks!

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