Add octan and add team (WIP)

This commit is contained in:
unurled 2025-07-03 22:16:45 +02:00
parent 744308d0cb
commit e841c38573
Signed by: unurled
GPG key ID: EFC5F5E709B47DDD
12 changed files with 575 additions and 42 deletions

View file

@ -200,4 +200,37 @@ class TournamentController extends Controller
return redirect()->route('home')
->with('success', 'Tournament deleted successfully!');
}
public function addTeam(Competition $tournament, Request $request)
{
// Check if user is tournament owner
if ($tournament->owner != Auth::id()) {
return redirect()->back()->with('error', 'You are not authorized to add a team to this tournament.');
}
// Validate the request data
$validator = Validator::make($request->all(), [
'team_id' => 'required|exists:teams,id',
]);
if ($validator->fails()) {
return redirect()->back()->withErrors($validator)->withInput();
}
// Add the team
$team = Team::find($request->team_id);
// if it doesn't exist, create new team
//
if (!$team) {
$team = new Team();
$team->name = $request->team_name;
$team->save();
}
$tournament->teams()->attach($team->id);
return redirect()->route('tournaments.show', $tournament->id)
->with('success', 'Team added successfully!');
}
}