Edit RelationManager pivot array data

Hi, I'm trying to create a form to update my pivot table data for a resale system. I have, in my Model Service, my relationship which includes the pivots:
public function providers(): BelongsToMany
{
return $this->belongsToMany(Provider::class, 'provider_services')
->using(ProviderServicePivot::class)
->withPivot('extra', 'is_enabled')
->withTimestamps();
}
public function providers(): BelongsToMany
{
return $this->belongsToMany(Provider::class, 'provider_services')
->using(ProviderServicePivot::class)
->withPivot('extra', 'is_enabled')
->withTimestamps();
}
And this is my ProviderServicePivot :
class ProviderServicePivot extends Pivot
{
public function casts(): array
{
return [
'extra' => 'array',
'is_enabled' => 'boolean',
];
}
}
class ProviderServicePivot extends Pivot
{
public function casts(): array
{
return [
'extra' => 'array',
'is_enabled' => 'boolean',
];
}
}
And on my form when i Try to access on extra.name property, it doesn't work.
public function form(Form $form): Form
{
return $form
->schema([
Forms\Components\Section::make(__('inputs.sections.infos'))
->columns(2)
->schema([
Forms\Components\TextInput::make('extra.name')
->label(__('inputs.generic.name'))
->maxLength(255)
->required()
]),
]);
}
public function form(Form $form): Form
{
return $form
->schema([
Forms\Components\Section::make(__('inputs.sections.infos'))
->columns(2)
->schema([
Forms\Components\TextInput::make('extra.name')
->label(__('inputs.generic.name'))
->maxLength(255)
->required()
]),
]);
}
Anyone have an idea of ​​the method to follow? Thank you so much,
Solution:
I've found solution. I need to mount my EditAction with pivot to array
Jump to solution
2 Replies
Solution
Alex'R
Alex'R2w ago
I've found solution. I need to mount my EditAction with pivot to array
Alex'R
Alex'ROP2w ago
php
GenericActions::edit()
->modalHeading(fn($record): string => __('modals.services.providers.heading', ['name' => $this->getOwnerRecord()->name, 'provider' => $record->name]))
->mountUsing(
fn($record, $form) => $form->fill($record->pivot->toArray())
),
php
GenericActions::edit()
->modalHeading(fn($record): string => __('modals.services.providers.heading', ['name' => $this->getOwnerRecord()->name, 'provider' => $record->name]))
->mountUsing(
fn($record, $form) => $form->fill($record->pivot->toArray())
),

Did you find this page helpful?