This commit is contained in:
Laucha1312
2026-06-04 15:15:23 -03:00
parent 0841794c50
commit 90c5f85512
167 changed files with 15870 additions and 0 deletions
@@ -0,0 +1,76 @@
<?php
namespace App\Http\Controllers;
use App\Models\Jugador;
use Illuminate\Http\Request;
class JugadorController extends Controller
{
public function index()
{
$jugadores = Jugador::with('clubActual', 'clubOrigen', 'equipos')->get();
return response()->json($jugadores);
}
public function show($id)
{
$jugador = Jugador::with('clubActual', 'clubOrigen', 'equipos')->findOrFail($id);
return response()->json($jugador);
}
public function store(Request $request)
{
$data = $request->validate([
'id_jugador' => 'nullable|string|max:6',
'documento' => 'required|string|max:20|unique:jugadores',
'nombre' => 'required|string|max:100',
'apellido' => 'required|string|max:100',
'fecha_nacimiento' => 'nullable|date',
'edad' => 'nullable|integer',
'categoria' => 'nullable|string|max:20',
'id_club_actual' => 'nullable|integer|exists:clubes,id_club',
'id_club_origen' => 'nullable|integer|exists:clubes,id_club',
'activo' => 'nullable|boolean',
'email' => 'nullable|email|max:150',
'telefono' => 'nullable|string|max:50',
'password' => 'nullable|string',
]);
if (isset($data['password'])) {
$data['password'] = bcrypt($data['password']);
}
$jugador = Jugador::create($data);
return response()->json($jugador, 201);
}
public function update(Request $request, $id)
{
$jugador = Jugador::findOrFail($id);
$data = $request->validate([
'documento' => 'sometimes|string|max:20|unique:jugadores,documento,' . $id . ',id_jugador',
'nombre' => 'sometimes|string|max:100',
'apellido' => 'sometimes|string|max:100',
'fecha_nacimiento' => 'nullable|date',
'edad' => 'nullable|integer',
'categoria' => 'nullable|string|max:20',
'id_club_actual' => 'nullable|integer|exists:clubes,id_club',
'id_club_origen' => 'nullable|integer|exists:clubes,id_club',
'activo' => 'nullable|boolean',
'email' => 'nullable|email|max:150',
'telefono' => 'nullable|string|max:50',
'password' => 'nullable|string',
]);
if (isset($data['password'])) {
$data['password'] = bcrypt($data['password']);
}
$jugador->update($data);
return response()->json($jugador);
}
public function destroy($id)
{
$jugador = Jugador::findOrFail($id);
$jugador->delete();
return response()->json(null, 204);
}
}