Nova pivot fields with custom pivot model
I've got a many to many relation that includes some pivot fields that I need to be editable in Nova (3), so I've set it up like this:
BelongsToMany::make('Orders')
->fields(
function () {
return [
Number::make('Quantity')
->default(1)
->min(1),
Select::make('Weekday')
->default(Weekdays::monday())
->options(array_combine(Weekdays::toValues(), Weekdays::toLabels()))
];
}
)
However, as you can see, that "weekday" field is an enum (Spatie), and could do with casting, so I'm introducing a custom model for my pivot to apply the cast. From what I've seen in other examples, the code should change to pass a pivot model instance to the fields method:
BelongsToMany::make('Orders')
->fields(new OrderSchedule())
But now it seems that the pivot fields are no longer available – where do I need to put the pivot field definitions for Nova? Do I need to make a separate Nova resource for the pivot model?
Please or to participate in this conversation.