bhdrnzl
bhdrnzl

Reputation: 61

to import double quotes with laravel json

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

Answers (2)

Shailendra Gupta
Shailendra Gupta

Reputation: 1128

Use this:

$data = ["ss,bb,nn"];
$data2 = explode(',',$data[0]);

Upvotes: 0

DPS
DPS

Reputation: 1003

You can use both implode and explode to get result. Assign it to variable and do processing then import

  1. remove braces from the array

     $myString =["ss,bb,nn"];
     $string = implode('', $myString);
    
  2. 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

Related Questions