Saved data not showing in multiselect field

What I am trying to do: Displaying the data that is picked from the multiselect. What I did: Made a new column in the database:
$table->json('value_types')->nullable();
$table->json('value_types')->nullable();
Set cast to array & added it as fillable in the model. Then in my resource added the following:
Select::make('value_types')
->label('Toon meter waarde')
->options([
'temperature' => 'Temperatuur',
'co2' => 'CO2',
'movement' => 'Beweging',
'pressure' => 'Druk',
'illuminance' => 'Verlichting',
'io_status' => 'IO Status',
'humidity' => 'Vochtigheid',
])
->searchable()
->multiple()
>columnSpan(2),
Select::make('value_types')
->label('Toon meter waarde')
->options([
'temperature' => 'Temperatuur',
'co2' => 'CO2',
'movement' => 'Beweging',
'pressure' => 'Druk',
'illuminance' => 'Verlichting',
'io_status' => 'IO Status',
'humidity' => 'Vochtigheid',
])
->searchable()
->multiple()
>columnSpan(2),
My issue/the error: Values are saved correctly in the database, but when i reopen the form the multiselect field is empty. So it's not showing the values i just saved. When i then save the fields again it saves an empty array.
9 Replies
Dennis Koch
Dennis Koch3mo ago
When you save and dump the data, what does it actually return? Like dd($yourModel->value_types)?
skyrowl
skyrowl3mo ago
Can you add ->rules(['array']) to your component ? I had a similar issue where the component needed to validate as an array for it to output the data
TheEvilTomat0
TheEvilTomat0OP3mo ago
Thanks for the replies! Will try it monday when i'm back at the office 🙂
TheEvilTomat0
TheEvilTomat0OP3mo ago
No description
TheEvilTomat0
TheEvilTomat0OP3mo ago
It shows when i just saved it, but when i refresh the page or go back to a different one it doesn't show it anymore
No description
toeknee
toeknee3mo ago
Did the database update? Do you have it as fillable on your model?
TheEvilTomat0
TheEvilTomat0OP3mo ago
Yes database did update
toeknee
toeknee3mo ago
Sounds like the data isn't being refresh, is this on a livewire componebnt?
TheEvilTomat0
TheEvilTomat0OP3mo ago
It's inside a resource

Did you find this page helpful?