FilamentF
Filament15mo ago
jamesro

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'
            ]);
    }


Car entity:

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(),


any how to make it work without having to rename those columns in my pivot table?
Was this page helpful?