Add octan and add team (WIP)
This commit is contained in:
parent
744308d0cb
commit
e841c38573
12 changed files with 575 additions and 42 deletions
|
@ -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!');
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue