lundi 4 novembre 2019

Laravel - Call to a member function save() on string

  • I am unable to save an array of items from session to mysql database with an error

    "Symfony \ Component \ Debug \ Exception \ FatalThrowableError (E_ERROR) Call to a member function save() on string"

  • When I do a dd(Dump and Die) the array is displayed as below

    "{"1":{"name":"Bajiya","quantity":4,"price":"34.00"}, "2":{"name":"Gulha","quantity":2,"price":"3.00"}, "3":{"name":"kavaabu","quantity":1,"price":"2.00"}}"

  • Below is the controller store function

public function storeCart(Request $request){

$cart = new Cart;
$cart= session()->get('cart');
$cart =  json_encode($cart);
$cart->save();

}

  • I have a table in my Database with columns for id and cart.
  • I want the array above to be saved in the cart column.
  • Thanks


via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire