F
Filamentβ€’8mo 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'),
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.
2 Replies
Dennis Koch
Dennis Kochβ€’8mo ago
->dehydrated(false)
Finn
FinnOPβ€’8mo ago
Perfect, that does the job. Thanks :). I knew there would be a better way than stripping it of before filling πŸ˜›
Want results from more Discord servers?
Add your server