@kxh Well what have you tried? What exactly are you stuck on?
Tournament System
Hello world,
Im trying to code a tournament system in laravel where users can join a tournament as single player or with teams and after that to generate brackets. Does anybody has some info for me, where can I start
Thanks in advance
If you follow a Cruddy By Design approach, then a separate controller would be used, e.g. TournamentEntriesController. Define a route to register the user in the tournament:
Route::post('tournaments/{tournament}/entries', [TournamentEntriesController::class, 'store'])->name('tournament_entries.store');
In that controller, you can define a store method which accepts the tournament id:
// TournamentEntriesController
public function store(Request $request, Tournament $tournament)
{
// If the authenticated user is registering for the tournament
$tournament->users()->attach(auth()->id());
return back();
}
The button needs only to be wrapped in a form:
<form action="{{ route('tournament_entries.store', $tournament) }}" method="POST">
@csrf
<button>Add</button>
</form>
This example assumes an authenticated user is joining a tournament; if you need to pick a User to assign to a tournament, then add a user_id field to the form.
Please or to participate in this conversation.