Morph relations saves *able_type column as model class' names. #45851
Answered
by
denizgolbas
tolgabrandt
asked this question in
Q&A
-
When i create a morph relational record with Eloquent i see directly the model class names in type columns. When i implement another model methods with "wherepivot", i can not get records because some backslashes not match with class names. How can i change morph relations to table name globally? |
Beta Was this translation helpful? Give feedback.
Answered by
denizgolbas
Jan 28, 2023
Replies: 1 comment
-
In your AppServiceProvider boot method(or you can create another provider):
Relation::morphMap([
'posts' => 'App\Models\Post',
'videos' => 'App\Models\Video',
]); More details: https://laravel.com/docs/master/eloquent-relationships#custom-polymorphic-types |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
tolgabrandt
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In your AppServiceProvider boot method(or you can create another provider):
Add:
More details: https://laravel.com/docs/master/eloquent-relationships#custom-polymorphic-types