3 namespace App\Http\Controllers;
5 use App\Events\ApplicationChanged;
6 use App\Events\ApplicationRemoved;
7 use App\Models\Application;
8 use App\Models\Participant;
9 use App\Models\Protocol;
10 use Illuminate\Http\Request;
12 class ApplicationController extends Controller
15 public function accept(Request $request, Application $application) {
16 $this->authorize('accept', $application);
18 $participant = Participant::firstOrCreate([
19 'tournament_id' => $application->tournament_id,
20 'user_id' => $application->user_id,
22 $participant->makeRunner();
24 $application->delete();
25 ApplicationRemoved::dispatch($application->id, $application->tournament_id);
27 Protocol::applicationAccepted($application->tournament, $application, $request->user());
29 return $participant->toJson();
32 public function reject(Request $request, Application $application) {
33 $this->authorize('reject', $application);
35 $application->denied = true;
37 ApplicationChanged::dispatch($application);
39 Protocol::applicationRejected($application->tournament, $application, $request->user());
41 return $application->toJson();