Disable data binding of Select Field

I want to save Statuses of my table using the Spatie Model Status Package. I have a dropdown on a Form, but I want to handle the data binding myself. At least that is how I think should be the approach? So I now get an error when saving the form. It looks like it still want to update the status field in my table, but that doesn't exist. This is my Select:
Select::make('status')
->label(__('strings.fields.status'))
->columnSpanFull()
->options([
'draft' => __('strings.statuses.draft'),
'reviewing' => __('strings.statuses.reviewing'),
'published' => __('strings.statuses.published'),
])
->reactive()
->afterStateHydrated(function (?Model $record, $set) {
// Set the status to the current status of the record (seems to work?)
$set('status', $record->status);
})
->afterStateUpdated(fn ($state, $record) => $record->setStatus($state, 'Status changed by '.auth()->user()->name)),
Select::make('status')
->label(__('strings.fields.status'))
->columnSpanFull()
->options([
'draft' => __('strings.statuses.draft'),
'reviewing' => __('strings.statuses.reviewing'),
'published' => __('strings.statuses.published'),
])
->reactive()
->afterStateHydrated(function (?Model $record, $set) {
// Set the status to the current status of the record (seems to work?)
$set('status', $record->status);
})
->afterStateUpdated(fn ($state, $record) => $record->setStatus($state, 'Status changed by '.auth()->user()->name)),
This is the error I get:
https://flareapp.io/share/v5pBAjkP
https://flareapp.io/share/v5pBAjkP
Anyone has an idea what I'm missing here?
5 Replies
Patrick Boivin
I'm not sure but I think the issue comes from the fact that status is not a column but is defined as an accessor on the model... Have you tried using a "dummy" column name? Something like this
Select::make('_status')
Select::make('_status')
and
$set('_status', ... )
$set('_status', ... )
Daniel Plomp
Daniel PlompOP2y ago
Thanks, that worked!
johnnie_littleshoes
Hi Daniel, did you just replace 'status' with '_status' and then it worked? I'm still struggling a bit
Daniel Plomp
Daniel PlompOP16mo ago
Yes, I did only changed that.
Dakaa
Dakaa13mo ago
@Daniel Plomp How do you render the tabel column?
Want results from more Discord servers?
Add your server