No morph map defined for model
I get the following error on the edit page of the User Resource on the admin panel and not sure what may be the issue
My form method has the following code
and the relation on the User model is as follows:
User model has the following additions from the default
15 Replies
the same code works with Filament v2, not sure what the issue is
I get that from LW3. Seems like if you use morph maps for any models, you have to add them for all models LW3 interacts with, even if you don't have any polymorphic relations to them. Don't know if that's a feature or a bug, just something I found when migrating one of my apps to v3.
could you elaborate what the fix is actually?
i get this error only on the filament admin panel
Do you use morph maps at all?
ya, am not sure what exactly to do to fix this issue
Try just adding your User model to your morph map. I had to add my User model to mine, even tho I have no polymorphic relations that use it.
If you don't have a morph map ... then I dunno.
ok
that worked
I think the last 3 in that map above I had to add just to shut LW3 up.
Thank you.
do you use Spatie's permission package?
I came across this https://ralphjsmit.com/laravel-fix-no-morph-map-defined
Ralph J. Smit
How to fix the Laravel “No morph map defined for model” error | RJS
In this tutorial I'll show you how to fix the Laravel "No morph map defined for model"-error quick & easy. I'll also explain why the error in Laravel exists.
changing to
morphMap
instead of enforceMorphMap
resolves this issue without having those.Ah, interesting! Thank you! And thank @ralphjsmit.
Yes, I do use Spatie permissions.
thats when it started creating this issue.
I am assuming they use morphs
They do
That's definitely a really useful tip from Ralph. Now I can just switch to using morphMap() instead of enforceMorphMap() and not worry about it.