@php $review = App\Models\Review::where('course_id', $bootcamp->id) ->orderBy('id', 'DESC') ->get(); $total = $review->count(); $rating = array_sum(array_column($review->toArray(), 'rating')); $average_rating = 0; if ($total != 0) { $average_rating = $rating / $total; } @endphp