tries to add api requests
This commit is contained in:
parent
e841c38573
commit
73c32b4fb6
26 changed files with 962 additions and 39 deletions
|
@ -10,6 +10,7 @@ use App\Models\User;
|
|||
use Illuminate\Http\Request;
|
||||
use Inertia\Inertia;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
|
||||
|
@ -201,19 +202,23 @@ class TournamentController extends Controller
|
|||
->with('success', 'Tournament deleted successfully!');
|
||||
}
|
||||
|
||||
public function addTeam(Competition $tournament, Request $request)
|
||||
public function addTeam(Request $request, Competition $tournament)
|
||||
{
|
||||
Log::info($request);
|
||||
// Check if user is tournament owner
|
||||
if ($tournament->owner != Auth::id()) {
|
||||
Log::error('User is not authorized to add a team to this tournament.');
|
||||
Log::error('userId: ' . Auth::id() . ' tournamentOwnerId: ' . $tournament->owner);
|
||||
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',
|
||||
'teamName' => 'required|exists:teams,string',
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
Log::error('Validation failed for addTeam', $validator->errors());
|
||||
return redirect()->back()->withErrors($validator)->withInput();
|
||||
}
|
||||
|
||||
|
@ -228,9 +233,8 @@ class TournamentController extends Controller
|
|||
}
|
||||
$tournament->teams()->attach($team->id);
|
||||
|
||||
|
||||
|
||||
return redirect()->route('tournaments.show', $tournament->id)
|
||||
->with('success', 'Team added successfully!');
|
||||
return response()->json([
|
||||
'tournament' => $tournament,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue