mercredi 21 août 2019

displaying most rated restaurants in laravel

I have this table reviews thats stores user's reviews with restaurants id.This is the store function for reviews.i need it to save the average rating and store it in the rating count column

    $review = new Review;

    $review->user_id = auth()->user()->id;
    $review->restaurant_id = $request->get('restaurant_id');
    $review->value = $request->input('value');
    $review->rating = $request->input('rating'); 
    $avgRating = $review->avg('rating');
    $review->rating_count = round($avgRating, 1);

    $review->save();

But this saves the rating value for each restaurant, it doesn't calculate the rating and increment it:

enter image description here

Help please, thanks in advance.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire