Home > Blockchain >  I get error: Trying to get property 'product' of non-object when I remove an object from m
I get error: Trying to get property 'product' of non-object when I remove an object from m

Time:07-21

This is my controller,I tried to change using if(Count( $newcart[products]) > 0) instead of if(Count( $newcart->products) > 0) but it didn't work enter image description here

CodePudding user response:

dd($newcart->products); 

if you get null so

dd($newcart); 

and see if it contains products

CodePudding user response:

public function delete($id)
{
    $items = session('cart');
    foreach ($items as $key => $date)
    {
        if ($date['id'] == $id)
        {
          unset($items [$key]);
        }
    }
    $request->session()->push('cart',$items);
    return redirect()->back();
}

Hope you can get idea from here and it helps you.

  • Related