LaravelShoppingcart icon indicating copy to clipboard operation
LaravelShoppingcart copied to clipboard

"Trying to get property of non-object". i am using Laravel 5.5,(gloudemans-2.4)

Open rakibul100636 opened this issue 6 years ago • 5 comments

class CartController extends Controller {

public function add_to_cart_function(Request $request){

 $qty=$request->qty;
 $product_id=$request->product_id;

// print_r($product_id); // print_r($qty); // exit(); $product_detail_info=DB::table('tbl_product') ->where('id',$product_id) ->first(); // echo '

';
//      print_r($product_info);
//      exit();
Cart::add([
'id' => $product_detail_info->product_id,
'name' => $product_detail_info->product_name,
'qty' => $qty,
'price' => $product_detail_info->product_price,
'options' => ['image' => $product_detail_info->image_name]
]);
}

}

rakibul100636 avatar Jan 17 '18 15:01 rakibul100636

Please format the code properly. :-) It’s unreadable right now. And give me more info. On which line are you getting the exception, what is the stacktrace, etc.

Crinsane avatar Jan 17 '18 18:01 Crinsane

when i am trying to access Card class " Cart::add....."

rakibul100636 avatar Jan 28 '18 16:01 rakibul100636

Try to clear the cart and try again, worked for me

abdelmoughit555 avatar May 12 '18 23:05 abdelmoughit555

I'm also getting the same error. ErrorException (E_NOTICE) Trying to get property 'product_name' of non-object.

IstiyakMilon avatar Aug 01 '19 05:08 IstiyakMilon

The error suggests that some code path tries to access the member 'product_name' on null. Can you provide more information on where you are receiving this error message (File and Line)?

bumbummen99 avatar Aug 02 '19 15:08 bumbummen99