I am working on a shopping application and now I have come to the next problem.
There is a User, Product, and Cart object.
- The Recycle Bin table contains only the following columns: "id", "user_id", "product_id" and timestamps.
- UserModel "hasMany" Carts (because the user can store multiple products).
- CartModel "belongs" to users and CartModel "hasMany".
Now, to calculate common products, I can just call: Auth::user()->cart()->count() .
My question is: how can I get the SUM () price (product column) of the products in the cart by this user?
I would like to do this with Eloquent and not with a query (mainly because I find it to be much cleaner).
php eloquent laravel relation
theAdmiral Feb 10 '14 at 14:20 2014-02-10 14:20
source share