samedi 24 juillet 2021

Error when saving json to database mysql?

public function store(Request $request)
{
  $image = ['http://localhost.loca/image/product/01-1627140249.jpg', 'http://localhost.loca/image/product/03-169983334.jpg'];
  $product = new Product();
  $product->image = json_encode($image);
  $product->save();
}

And the results are stored in the database

["http:\/\/localhost.loca\/image\/product\/01-1627140249.jpg","http:\/\/localhost.loca\/image\/product\/03-169983334.jpg"]

There are \ being generated. is there any fix. Thanks.

Update I use : JSON_UNESCAPED_SLASHES

[\"http://localhost.loca/image/product/01-1627140249.jpg\", \"http://localhost.loca/image/product/03-169983334.jpg\"]

it still has a \ at the beginning and end of the link



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire