auditionadmin/app/Http/Controllers/Judging/BonusScoreEntryController.php

32 lines
1.1 KiB
PHP

<?php
namespace App\Http\Controllers\Judging;
use App\Http\Controllers\Controller;
use App\Models\BonusScore;
use App\Models\BonusScoreDefinition;
use App\Models\Entry;
use Illuminate\Support\Facades\Auth;
use function redirect;
class BonusScoreEntryController extends Controller
{
public function __invoke(Entry $entry)
{
if (BonusScore::where('entry_id', $entry->id)->where('user_id', Auth::user()->id)->exists()) {
return redirect()->route('judging.bonusScore.EntryList', $entry->audition)->with('error', 'You have already judged that entry');
}
/** @var BonusScoreDefinition $bonusScore */
$bonusScore = $entry->audition->bonusScore()->first();
if (! $bonusScore->judges->contains(auth()->id())) {
return redirect()->route('judging.index')->with('error', 'You are not assigned to judge this entry');
}
$maxScore = $bonusScore->max_score;
$bonusName = $bonusScore->name;
return view('judging.bonus_entry_score_sheet', compact('entry', 'maxScore', 'bonusName'));
}
}