Relation manager with intermediate relationship
Hi
Let's say I've an entity
Foo
that has many Bar
, where Bar
belongs to many Baz
. Is that possible to have a relation manager for Foo
listing the related Baz
? 🤔
As far as I know, relation managers are based on Laravel Eloquent's relationships, and this isn't a base relationship. I cleary see how to retrieve these records using SQL joins, but not how to make it works with the awesome relation manager feature.
Thanks 🙏12 Replies
Did you try it with a hasManyThrough relationship.? Don’t have much experience with them. But that’s what it sounds like to me.
It doesn't handle the belongs to many relationship. I'd rather need a belongsToManyThroughMany 😄
Sounds horrible.
I need to display the courses related to the school 😉
It would be way more convenient than having to open a specific specialism
It's deadly simple to have a sql query, but not to plug it to the ❤️ relation manager
Have you looked at the Attach actions?
Relation managers still have a query that you can modify to use with joins.
They’re still just a table from the tables package.
Oh, that sounds interesting 🤔 I'll look into that. I guess it's unusual thus not documented 😅
Filament
Relation managers - Resources - Admin Panel - Filament
The elegant TALL stack admin panel for Laravel artisans.
Hmm ok I see the attaching actions. I've found out that there is indeed the
getTableQuery
method, which is possible to override. However I don't see how it's possible to write it 😅 Is there a specific way to get the query builder as I don't have a relationship? Or should I give the specialisms
relationship, serving as a start point? 🤔I’d probably create a pivot table linking the three, but yea you’re going to need a relationship either way, whether that’s a through or with pivot data.
This morning you inspired me a solution based on a view, adding the school ID on the course, creating a dedicated
CourseSchool
model just for the table. I guess then I can override the urls for the actions 🤔 (to actually use the Course
model)
I indeed actually solved it using a view like so:
This way I can simulate a School::belongsToMany(Course::class, 'course_slug')
behavior 👍
I guess I just miss the associate/dissociate features as a view is readonly, but it should be ok for us
Thanks for your help 🙏Glad you got it working.