Reputation: 1500
I Have 2 table:
stores
store_feedbacks | store_id , user_id ,rating
rating is number between 1-5 , Now I want to get average of all rating for one store,How I can do it?
Upvotes: 0
Views: 1233
Reputation: 25404
Assuming your relationships are correctly set up:
$store->ratings()->avg();
Docs: https://laravel.com/docs/5.7/queries#aggregates - they're from the queries page, but it applies to Eloquent as well.
Upvotes: 3