php - Undefined property: Illuminate\Database\Eloquent\Builder::$id Laravel 5.4 -


what want add product shopping cart. after click add cart button , undefined property error. take code https://www.codetutorial.io/the-shopping-cart-how-to-craft-an-e-shop-with-laravel/. can clarify error. :)

product.blade.php

  @foreach ($id $id)     <div class="caption">      <div class="row">       <div class="col-md-6 col-xs-6">       <h3>{{$id->name}}</h3>       </div>       <div class="col-md-6 col-xs-6 price">        <h3>        <label>rm {{$id->price}}</label></h3>          </div>      <div class="col-md-6 col-md-offset-3">      <a href="{{ route('addproduct',$id->product_id) }}" class="btn btn-      success btn-product"><span class="fa fa-shopping-cart"></span>add       cart</a></div>          </div>          </div>            </div>            </div>           @endforeach 

cartcontroller.php

public function __construct() {$this->middleware('auth');}  public function additem ($productid){     $cart = cart::where('user_id',auth::user()->id);     if(!$cart){        $cart =  new cart();        $cart->user_id=auth::user()->id;        $cart->save();    }     $cartitem  = new cartitem();    $cartitem->product_id=$productid;    $cartitem->cart_id= $cart->id;    $cartitem->save();    return redirect('/viewcart');    }    public function showcart(){   $cart = cart::where('user_id',auth::user()->id);     if(!$cart){        $cart =  new cart();        $cart->user_id=auth::user()->id;        $cart->save();    }     $items = $cart->cartitems;    $total=0;    foreach($items $item){        $total+=$item->product->price;    }     return view('viewcart',['items'=>$items,'total'=>$total]);} 

viewcart.blade.php

 @foreach ($items $item)   <tr><td class="col-sm-8 col-md-6"> <div class="media">  <a class="thumbnail pull-left" href="#"> <img class="media-object" src="  {{$item->product->image}}" style="width: 100px; height: 72px;"> </a>  <div class="media-body">  <h4 class="media-heading"><a href="#">{{$item->product->name}}</a></h4>  </div></div></td>      <td class="col-sm-1 col-md-1 text-center"><strong>{{$item->product>price}}   </strong></td>  <td class="col-sm-1 col-md-1">  <a href="/removeitem/{{$item->id}}"> <button type="button" class="btn btn-  danger">  <span class="fa fa-remove"></span> remove   </button></a></td></tr>       @endforeach 

update cart_items database


Comments

Popular posts from this blog

Sort a complex associative array in PHP -

vb.net - How to ignore if a cell is empty nothing -

recursion - Can every recursive algorithm be improved with dynamic programming? -