Reputation: 61
current record;
["ss,bb,nn"]
want to save as follows;
["ss","bb","nn"]
my model;
protected $casts = [
'options' => 'array',
];
my controller;
$cpoll->options = $request->options;
Upvotes: 1
Views: 477
Reputation: 1128
Use this:
$data = ["ss,bb,nn"];
$data2 = explode(',',$data[0]);
Upvotes: 0
Reputation: 1003
You can use both implode and explode to get result. Assign it to variable and do processing then import
remove braces from the array
$myString =["ss,bb,nn"];
$string = implode('', $myString);
explode it using comma(,)
$myArray = explode(',', $string );
So finally code will be
$myString = ["ss,bb,nn"];
$string = implode('', $myString);
$myArray = explode(',', $string);
return $myArray;
Upvotes: 2