Support the ongoing development of Laravel.io →
Database Eloquent

Assuming I have the following models:

  • FeedItem (Polymorphic)
  • Facebook (has many tags)
  • Twitter (has many tags)
  • Tag

What I'd like to be able to do is

FeedItem::with(['feedable.tags' => function ($q) { 
    $q->where('tag.name', 'my-tag');
}])->get()

But the feedable relationship seems to get ignored when I try to eager-load it.

If I do a dd('exiting'); within the anonymous function, it never gets called.

Any ideas how I can scope the related model?

Last updated 3 years ago.
0

Sign in to participate in this thread!

PHPverse

Your banner here too?

amo amo Joined 3 Sep 2015

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.