3 namespace App\Http\Controllers;
5 use App\Events\ResultReported;
6 use App\Models\Participant;
7 use App\Models\Protocol;
10 use Illuminate\Http\Request;
12 class ResultController extends Controller
15 public function create(Request $request) {
16 $validatedData = $request->validate([
17 'participant_id' => 'required|exists:App\\Models\\Participant,id',
18 'round_id' => 'required|exists:App\\Models\\Round,id',
19 'time' => 'required|numeric',
22 $participant = Participant::findOrFail($validatedData['participant_id']);
23 $round = Round::findOrFail($validatedData['round_id']);
25 $user = $request->user();
26 if ($user->id != $participant->user->id) {
27 $this->authorize('create', Result::class);
30 $result = Result::updateOrCreate([
31 'round_id' => $validatedData['round_id'],
32 'user_id' => $participant->user_id,
34 'time' => $validatedData['time'],
37 Protocol::resultReported(
43 ResultReported::dispatch($result);
45 return $result->toJson();