| 123456789101112131415161718192021222324252627282930313233343536373839 |
- <?php
- namespace App\Http\Controllers;
- use App\Services\StudentResponsibleService;
- use App\Http\Requests\StudentResponsibleRequest;
- use App\Http\Resources\StudentResponsibleResource;
- use Illuminate\Http\JsonResponse;
- class StudentResponsibleController extends Controller
- {
- public function __construct(
- protected StudentResponsibleService $service,
- ) {}
- public function getByStudent(int $studentId): JsonResponse
- {
- $item = $this->service->getByStudentId($studentId);
- return $this->successResponse(payload: $item ? new StudentResponsibleResource($item) : null);
- }
- public function store(StudentResponsibleRequest $request): JsonResponse
- {
- $item = $this->service->create($request->validated());
- return $this->successResponse(payload: new StudentResponsibleResource($item), message: __('messages.created'), code: 201);
- }
- public function update(StudentResponsibleRequest $request, int $id): JsonResponse
- {
- $item = $this->service->update($id, $request->validated());
- return $this->successResponse(payload: new StudentResponsibleResource($item), message: __('messages.updated'));
- }
- public function destroy(int $id): JsonResponse
- {
- $this->service->delete($id);
- return $this->successResponse(message: __('messages.deleted'), code: 204);
- }
- }
|