@php $review = App\Models\Review::where('course_id', $course->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; } $wishlist = App\Models\Wishlist::where('user_id', auth()->user()->id ?? '')->pluck('course_id')->toArray(); @endphp