79 lines
2.0 KiB
PHP
79 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Models\Modalidad;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\Request;
|
|
|
|
class ModalidadController extends Controller
|
|
{
|
|
/**
|
|
* Display a listing of the resource.
|
|
*/
|
|
public function index(): JsonResponse
|
|
{
|
|
$items = Modalidad::all();
|
|
|
|
return response()->json([
|
|
'success' => true,
|
|
'data' => $items,
|
|
'message' => 'Registros obtenidos correctamente',
|
|
], 200);
|
|
}
|
|
|
|
/**
|
|
* Store a newly created resource in storage.
|
|
*/
|
|
public function store(Request $request): JsonResponse
|
|
{
|
|
$payload = $request->only((new Modalidad())->getFillable());
|
|
$modalidad = Modalidad::create($payload);
|
|
|
|
return response()->json([
|
|
'success' => true,
|
|
'data' => $modalidad,
|
|
'message' => 'Registro creado correctamente',
|
|
], 201);
|
|
}
|
|
|
|
/**
|
|
* Display the specified resource.
|
|
*/
|
|
public function show(Modalidad $modalidad): JsonResponse
|
|
{
|
|
return response()->json([
|
|
'success' => true,
|
|
'data' => $modalidad,
|
|
'message' => 'Registro obtenido correctamente',
|
|
], 200);
|
|
}
|
|
|
|
/**
|
|
* Update the specified resource in storage.
|
|
*/
|
|
public function update(Request $request, Modalidad $modalidad): JsonResponse
|
|
{
|
|
$payload = $request->only((new Modalidad())->getFillable());
|
|
$modalidad->update($payload);
|
|
|
|
return response()->json([
|
|
'success' => true,
|
|
'data' => $modalidad,
|
|
'message' => 'Registro actualizado correctamente',
|
|
], 200);
|
|
}
|
|
|
|
/**
|
|
* Remove the specified resource from storage.
|
|
*/
|
|
public function destroy(Modalidad $modalidad): JsonResponse
|
|
{
|
|
$modalidad->delete();
|
|
|
|
return response()->json([
|
|
'success' => true,
|
|
'message' => 'Registro eliminado correctamente',
|
|
], 200);
|
|
}
|
|
} |