LaravelShoppingcart
LaravelShoppingcart copied to clipboard
"Trying to get property of non-object". i am using Laravel 5.5,(gloudemans-2.4)
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] ]); }}
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.
when i am trying to access Card class " Cart::add....."
Try to clear the cart and try again, worked for me
I'm also getting the same error. ErrorException (E_NOTICE) Trying to get property 'product_name' of non-object.
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)?