Setting data field value on hidden field when submitting form.

I have a field, that I want it to be hidden, but still send data onwards after submitting a form. I've tried various different things directly in $form on the field in question, but simply can't get it to work. I can set a value, but the field does not get passed onwards. The only workaround I found was to set value directly in class through boot() function:
public static function boot()
{
parent::boot();

static::creating(function ($profileFeedback) {
$profileFeedback->account_id = Filament::getTenant()->id;
});

static::updating(function ($profileFeedback) {
$profileFeedback->account_id = Filament::getTenant()->id;
});
}
public static function boot()
{
parent::boot();

static::creating(function ($profileFeedback) {
$profileFeedback->account_id = Filament::getTenant()->id;
});

static::updating(function ($profileFeedback) {
$profileFeedback->account_id = Filament::getTenant()->id;
});
}
However, when I try to do any of the below given combinations, I just can't get it to work, any ideas?
Forms\Components\TextInput::make('account_id')
->required()
->hidden()
// ->dehydrateStateUsing(fn ($set) => $set('account_id', Filament::getTenant()->id))
// ->reactive()
// ->visible(false)
// ->dehydrated()
// ->afterStateHydrated(function ($set) {
// $set('account_id', Filament::getTenant()->id);
// })
// ->afterStateUpdated(function (Closure $set) {
// $set('account_id', Filament::getTenant()->id);
// })
// ->visible(false)
// ->default(Filament::getTenant()->id)
])
Forms\Components\TextInput::make('account_id')
->required()
->hidden()
// ->dehydrateStateUsing(fn ($set) => $set('account_id', Filament::getTenant()->id))
// ->reactive()
// ->visible(false)
// ->dehydrated()
// ->afterStateHydrated(function ($set) {
// $set('account_id', Filament::getTenant()->id);
// })
// ->afterStateUpdated(function (Closure $set) {
// $set('account_id', Filament::getTenant()->id);
// })
// ->visible(false)
// ->default(Filament::getTenant()->id)
])
Field simply doesn't get passed in any way.
No description
2 Replies
toeknee
toeknee2w ago
basically account_id doesn't have a default value in the DB. You need to scope it and not set it as per the docs. https://filamentphp.com/docs/3.x/panels/resources/creating-records#customizing-data-before-saving
lukaveck1
lukaveck1OP2w ago
Thanks, solved.

Did you find this page helpful?