Replies: 1 comment 1 reply
-
|
Hi there, You should define an intermediate model as described in the documentation: https://laravel.com/docs/10.x/eloquent-relationships#defining-custom-intermediate-table-models and define the default attributes using Also do note that |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Description:
Same issue as #3639 which was eventually implemented for
BelongsToMany.Say we have a
Musicmodel with acontributablespivot which can morph to eitherSingerorProducermodels.The pivot also has an
examplefield as defined below:app/Models/Music.php
When I run the below code
New record added to
contributablestable:However, when doing this in nova the
some singer valueandsome producer valueare not inserted:app/Nova/MusicResource.php
Because
exampleis not nullable it will give the following error when trying to attach:Workaround:
Define hidden fields with default values on the field
app/Nova/MusicResource.php
Fix
MorphedResourceAttachControllerneeds to have an equivalent of theLaravel\Nova\Query\Mixin\BelongsToMany::getDefaultPivotAttributes()method that theResourceAttachControlleruses to apply the default values.Beta Was this translation helpful? Give feedback.
All reactions