lundi 23 juillet 2018

Trying to get property 'id' of non-object in laravel session foreach

Im practicing laravel and right now Im in the session topic

this is my controller

public function set(Request $request){
   $product = Product::findOrFail($request->input('id'));
   session()->put('product', $product);
   return redirect()->route('cart');
 }

when i tried to echo the on my blade it produce an output of

{
  "id":9,
  "name":"Lorem ipsum dolor sit amet",
  "description":"Proin pretium, mauris id convallis tempus, lorem enim tincidunt nulla, vel pharetra sapien odio eget ligula. Sed maximus, massa sit amet condimentum bibendum, nisi ante vestibulum ipsum, ut ornare justo lorem mollis justo.",
  "price":"22.21",
  "cover_image":"JRwg9TSKTvUTvuij.jpg",
  "created_at":"2018-07-20 03:47:57",
  "updated_at":"2018-07-20 03:47:57"
}

but when i tried to use foreach on it by using

@foreach(session()->get('product') as $key)
        
@endforeach

it shows an error of Trying to get property 'id' of non-object

can someone guide me why I'm I getting this error thanks.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire