mardi 29 décembre 2015

saving JSON string in laravel

I am trying to save a JSON string to the database.

this is the error that I get:

exception 'ErrorException' with message 'preg_replace(): Parameter mismatch, pattern is a string while replacement is an array

And this is how my JSON looks like:

"metadata": {
      "is_ivr": 0,
      "is_upgradable": 1,
      "is_sms": 0,
      "is_design": 0,
      "threshold_amount": 0,
      "post_threshold": 0,
      "pre_threshold": 0
    }

I want to save the value of metadata as string.

I tried doing this:

$data = $request->input('data');
$data['metadata'] = json_encode($data['metadata']);

Result of dd($data);

array:8 [
  "product_name" => "Pulse"
  "parent_product" => 0
  "product_description" => "goes here"
  "metadata" => array:7 [
    "is_ivr" => 0
    "is_upgradable" => 1
    "is_sms" => 0
    "is_design" => 0
    "threshold_amount" => 0
    "post_threshold" => 0
    "pre_threshold" => 0
  ]
  "price_period" => 1
  "price_variation" => 2
  "outlet_pricing" => 0
  "status" => 1
  ]
]



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire