samedi 14 janvier 2017

Laravel 5.1 Call to undefined method Illuminate\Database\Query\Builder::cartItems()

I have the following model and controller but it keeps throwing error:

Call to undefined method Illuminate\Database\Query\Builder::cartItems()

This is my model and controller:

 class Cart extends Model
{
    protected $fillable = [
       'user_id',
       'coupon_id',
    ];

    public function cartItems()
    {
       return $this->hasMany('App\CartItem');
    }

}


class CartController extends Controller
{


    public function index()
    {

       $userId = Auth::user()->id;

       $cart =  Cart::where('user_id', '=', $userId); 

       $cartItems = $cart->cartItems()->get();

       //...some other stuff...

       return view('cart.index', compact('cartItems'));
    }

 }



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire