Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
[5.4] whereHas on polymorphic relations not work #18523
when try whereHas method on a polymorphic relation does not works as expected.
i'm currently using this code in my own project
my Model (\App\Production\Models\Production Model)
and it works for my use case.
please note that all model related to \App\Production\Models\Production model have 'panen_future_date' filed in its table.
i have reproduced in a fresh laravel project. here is the https://github.com/bunnypro/querying-polymorphic
just migrate and use DummySeeder class for seeding.
and It's the code to return object to view:
The hint and the strange thing on the same is:
If I do this loop, for NOTHING, it work well and i can use on blade it:
and it on vue:
I hope it help
@themsaid I've thought of a semi-solution after discussing this with another developer. It does have a fairly big caveat, but I still think it's better than nothing... Basically:
[ User::class, Post::class, Comment::class, ]
We know that the
[ 'user' => User::class, 'post' => Post::class, 'comment' => Comment::class, ]
We cannot be sure what the table name is. As such, the solution is... Ugly. We can loop over the morph map, running