FilamentF
Filament2y ago
Finn

Best way to create a virtual/fake input?

I have the following fields:

Select::make('type_fake')
    ->label('Collectie type')
    ->options([
        'main' => 'Hoofd collectie',
        'has_parent' => 'Sub collectie (valt onder andere collectie)',
    ])
    ->native(false)
    ->default('main')
    ->live()
    ->required(),

Select::make('parent_id')
    ->label('Sub collectie van')
    ->options(ShopCollection::query()->whereNull('parent_id')->pluck('name', 'id'))
    ->searchable()
    ->preload()
    ->native(false)
    ->required()
    ->visible(fn (Get $get) => $get('type_fake') === 'has_parent'),


The parent_id only comes up when has_parent has been selected as a value in the type_fake select.
So the first select should not be inserted/filled into the Model. Is there a way to define a field is a fake/virtual field which should not be saved in the eloquent model? So I can avoid the SQLSTATE[42S22]: Column not found: 1054 Unknown column 'type_fake' in 'field list' error.
Was this page helpful?