first commit
Some checks failed
Build / run (push) Has been cancelled

This commit is contained in:
maher
2025-10-29 11:42:25 +01:00
commit 703f50a09d
4595 changed files with 385164 additions and 0 deletions

View File

@@ -0,0 +1,32 @@
<?php
namespace App\Actions\Reviews;
use App\Models\Review;
use Illuminate\Support\Facades\DB;
class UpdateReviewableAverageScore
{
public function execute(int $reviewableId, string $reviewableType): void
{
$votes = app(Review::class)
->where('reviewable_type', $reviewableType)
->where('reviewable_id', $reviewableId)
->select(
DB::raw('avg(`score`) as average'),
DB::raw('count(*) as count'),
)
->first();
$average = number_format((float) $votes['average'], 1);
// title or episode
$model = app(modelTypeToNamespace($reviewableType))->find(
$reviewableId,
);
$model->local_vote_average = $average;
$model->local_vote_count = $votes['count'];
$model->save();
}
}