I have a form with a series of checkboxes. The name of the checkboxes is name="groups[]"
.
<input type="checkbox" name="groups[]" value="value-1">
<input type="checkbox" name="groups[]" value="value-2">
<input type="checkbox" name="groups[]" value="value-3">
<input type="checkbox" name="groups[]" value="value-4">
I want to save the values submitted to a column named groups
in a MySQL database. My Laravel update code is as follows:
$record->groups = $attributes['groups'];
$record->save();
I have also tried:
$record->groups = implode(',', $attributes['groups']);
$record->save();
Just in case it helps, the field details in the migration file is:
$table->set('groups', ['value-1','value-2','value-3','value-4'])->nullable();
The error receiving is:
SQLSTATE[01000]: Warning: 1265 Data truncated for column 'groups' at row 1 (SQL: update `table` set `groups` = ["value-1","value-2"] where `id` = 1)
Is my update code incorrect for Laravel and Set columns?
I tried Googling a lot, but because the term set
is used in regular update queries, I'm not getting helpful results.
Edit: Added Table Structure
Column | Type |
---|---|
id | bigint(20) |
groups | set('value-1','value2','value-3','value-4') |
Edit: Results of my attributes:
array: 1 [▼
"groups" => array:2 [▼
0 => "value-1"
1 => "value-2"
]
]
'''