namespace App\Http\Controllers;
+use App\Events\ApplicationAdded;
+use App\Models\Application;
use App\Models\Tournament;
use Illuminate\Auth\Access\AuthorizationException;
use Illuminate\Http\Request;
class TournamentController extends Controller
{
+ public function apply(Request $request, Tournament $tournament) {
+ $this->authorize('apply', $tournament);
+ $application = new Application();
+ $application->tournament_id = $tournament->id;
+ $application->user_id = $request->user()->id;
+ $application->save();
+ ApplicationAdded::dispatch($application);
+ return $tournament->toJson();
+ }
+
public function single(Request $request, $id) {
$tournament = Tournament::with(
+ 'applications',
+ 'applications.user',
'rounds',
'rounds.results',
'participants',