You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
114 lines
4.0 KiB
PHP
114 lines
4.0 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Administracion;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\ProcesoAdmision;
|
|
use App\Models\ProcesoAdmisionDetalle;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Storage;
|
|
use Illuminate\Validation\Rule;
|
|
|
|
class ProcesoAdmisionDetalleController extends Controller
|
|
{
|
|
// GET /api/admin/procesos-admision/{procesoId}/detalles?tipo=requisitos
|
|
public function index(Request $request, $procesoId)
|
|
{
|
|
ProcesoAdmision::findOrFail($procesoId);
|
|
|
|
$q = ProcesoAdmisionDetalle::query()->where('proceso_admision_id', $procesoId);
|
|
|
|
if ($request->filled('tipo')) {
|
|
$q->where('tipo', $request->string('tipo'));
|
|
}
|
|
|
|
return response()->json($q->orderByDesc('id')->get());
|
|
}
|
|
|
|
// POST /api/admin/procesos-admision/{procesoId}/detalles (multipart/form-data)
|
|
public function store(Request $request, $procesoId)
|
|
{
|
|
ProcesoAdmision::findOrFail($procesoId);
|
|
|
|
$data = $request->validate([
|
|
'tipo' => ['required', Rule::in(['requisitos','pagos','vacantes','cronograma'])],
|
|
'titulo_detalle' => ['required','string','max:255'],
|
|
'descripcion' => ['nullable','string'],
|
|
|
|
'listas' => ['nullable','array'],
|
|
'meta' => ['nullable','array'],
|
|
|
|
'url' => ['nullable','string','max:500'],
|
|
|
|
'imagen' => ['nullable','image','mimes:jpg,jpeg,png,webp','max:10240'],
|
|
'imagen_2' => ['nullable','image','mimes:jpg,jpeg,png,webp','max:10240'],
|
|
]);
|
|
|
|
$data['proceso_admision_id'] = (int) $procesoId;
|
|
|
|
if ($request->hasFile('imagen')) {
|
|
$data['imagen_path'] = $request->file('imagen')->store('admisiones/detalles', 'public');
|
|
}
|
|
if ($request->hasFile('imagen_2')) {
|
|
$data['imagen_path_2'] = $request->file('imagen_2')->store('admisiones/detalles', 'public');
|
|
}
|
|
|
|
$detalle = ProcesoAdmisionDetalle::create($data);
|
|
|
|
return response()->json($detalle, 201);
|
|
}
|
|
|
|
// GET /api/admin/detalles-admision/{id}
|
|
public function show($id)
|
|
{
|
|
return response()->json(ProcesoAdmisionDetalle::findOrFail($id));
|
|
}
|
|
|
|
// PATCH /api/admin/detalles-admision/{id} (multipart/form-data)
|
|
public function update(Request $request, $id)
|
|
{
|
|
$detalle = ProcesoAdmisionDetalle::findOrFail($id);
|
|
|
|
$data = $request->validate([
|
|
'tipo' => ['sometimes', Rule::in(['requisitos','pagos','vacantes','cronograma'])],
|
|
'titulo_detalle' => ['sometimes','string','max:255'],
|
|
'descripcion' => ['sometimes','nullable','string'],
|
|
|
|
'listas' => ['sometimes','nullable','array'],
|
|
'meta' => ['sometimes','nullable','array'],
|
|
|
|
'url' => ['sometimes','nullable','string','max:500'],
|
|
|
|
'imagen' => ['sometimes','nullable','image','mimes:jpg,jpeg,png,webp','max:10240'],
|
|
'imagen_2' => ['sometimes','nullable','image','mimes:jpg,jpeg,png,webp','max:10240'],
|
|
]);
|
|
|
|
if ($request->hasFile('imagen')) {
|
|
if ($detalle->imagen_path) Storage::disk('public')->delete($detalle->imagen_path);
|
|
$data['imagen_path'] = $request->file('imagen')->store('admisiones/detalles', 'public');
|
|
}
|
|
|
|
if ($request->hasFile('imagen_2')) {
|
|
if ($detalle->imagen_path_2) Storage::disk('public')->delete($detalle->imagen_path_2);
|
|
$data['imagen_path_2'] = $request->file('imagen_2')->store('admisiones/detalles', 'public');
|
|
}
|
|
|
|
$detalle->update($data);
|
|
|
|
return response()->json($detalle->fresh());
|
|
}
|
|
|
|
// DELETE /api/admin/detalles-admision/{id}
|
|
public function destroy($id)
|
|
{
|
|
$detalle = ProcesoAdmisionDetalle::findOrFail($id);
|
|
|
|
if ($detalle->imagen_path) Storage::disk('public')->delete($detalle->imagen_path);
|
|
if ($detalle->imagen_path_2) Storage::disk('public')->delete($detalle->imagen_path_2);
|
|
|
|
$detalle->delete();
|
|
|
|
return response()->json(['message' => 'Detalle eliminado']);
|
|
}
|
|
}
|