I have three tables user, product and purchases. I am currently trying to create a user page but i am struggling to work out how i would give the user a list based on the category of the product they have purchased most.
USER: id, name Products: id, name, category Purchases: id, user_id, product_id
Here is what i've tried to bring back a counted list of the categories of products a user has purchased most:
$scategory = Purchase::with('products')
->where('purchases.products_id', '=', 'products_id')
->Where('purchases.user_id', '=', Auth::user()->id)
->withCount('purchases.category')
->orderBy('purchases_category', 'DESC')
->get();
and i get this error
Call to undefined method Illuminate\Database\Query\Builder::products.category()
How do i get a list of the categories of products the user has purchased most?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire