Relation manager with pivot table doesn't show pivot table field values when edit

Hello, I have these relation on my User and Cars entities: User entity:
public function cars(): BelongsToMany
{
return $this->belongsToMany(Cars::class, 'user_cars', 'id_user', 'id_car')
->withPivot([
'data_start', 'data_end', 'disabled'
]);
}
public function cars(): BelongsToMany
{
return $this->belongsToMany(Cars::class, 'user_cars', 'id_user', 'id_car')
->withPivot([
'data_start', 'data_end', 'disabled'
]);
}
Car entity:
public function owners()
{
return $this->belongsToMany(User::class, 'user_cars', 'id_car', 'id_user')
->withPivot('data_start', 'data_end', 'disabled');
}
public function owners()
{
return $this->belongsToMany(User::class, 'user_cars', 'id_car', 'id_user')
->withPivot('data_start', 'data_end', 'disabled');
}
Unfortunately, both my User entity and user_cars pivot table have these 3 colums on them: 'data_start', 'data_end', 'disabled' Now when i try to edit an entry from user_cars using my relation manager, those 3 columns values does not get the values from the db, it works if I rename columns to something else in my pivot table: This is relation manager form:
Forms\Components\DateTimePicker::make('data_start')
->required(),
Forms\Components\DateTimePicker::make('data_end')
->required(),
Forms\Components\Toggle::make('disabled')
->inline(false)
->required(),
Forms\Components\DateTimePicker::make('data_start')
->required(),
Forms\Components\DateTimePicker::make('data_end')
->required(),
Forms\Components\Toggle::make('disabled')
->inline(false)
->required(),
any how to make it work without having to rename those columns in my pivot table?
1 Reply
jamesro
jamesroOP3mo ago
sorted, change the relation manager form to this:
public function form(Form $form): Form
{
return $form
->schema([
Forms\Components\DateTimePicker::make('pivot_data_start')
->label('Data start')
->required(),
Forms\Components\DateTimePicker::make('pivot_data_end')
->required(),
Forms\Components\Toggle::make('pivot_disabled')
->mutateDehydratedStateUsing(function ($data) {
dd($data);
})
->inline(false)
->required(),
]);
}
public function form(Form $form): Form
{
return $form
->schema([
Forms\Components\DateTimePicker::make('pivot_data_start')
->label('Data start')
->required(),
Forms\Components\DateTimePicker::make('pivot_data_end')
->required(),
Forms\Components\Toggle::make('pivot_disabled')
->mutateDehydratedStateUsing(function ($data) {
dd($data);
})
->inline(false)
->required(),
]);
}
and now edit works just fine
Want results from more Discord servers?
Add your server