File manager - Edit - /var/www/html/homologBancodetalentos/app/Http/Controllers/TalentBank/Candidate/EducationController.php
Back
<?php namespace App\Http\Controllers\TalentBank\Candidate; use App\Http\Controllers\Controller; use App\Http\Requests\TalentBank\Candidate\EducationRequest; use App\Http\Resources\TalentBank\Candidate\EducationCollection; use App\Http\Resources\TalentBank\Candidate\EducationResource; use App\Http\Services\TalentBank\Candidate\EducationService; use App\Models\TalentBank\Candidate\Education; use Exception; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; use Illuminate\Support\Facades\DB; class EducationController extends Controller { private EducationService $educationService; public function __construct() { $this->educationService = new EducationService(); $this->middleware('auth.permissions:talent-bank-user-candidate,gestao-de-usuarios'); } public function index(Request $request) { try { $response = $this->educationService->index($request); return response()->json([ 'data' => new EducationCollection($response), 'message' => __('validation.success'), ], JsonResponse::HTTP_OK); } catch (Exception $e) { return response()->json( ['message' => $e->getMessage()], JsonResponse::HTTP_INTERNAL_SERVER_ERROR ); } } public function show(Education $education) { $response = $this->educationService->show($education); return response()->json([ 'data' => ['education' => new EducationResource($response)], 'message' => __('validation.success'), ], JsonResponse::HTTP_OK); } public function store(EducationRequest $request) { try { $candidate = $request->talentBankUser; DB::beginTransaction(); $response = $this->educationService->store($request, $candidate); DB::commit(); return response()->json([ 'message' => __('crud.message.insert', ['model' => __('crud.model.talent_bank.education')]), 'education' => new EducationResource($response), ], JsonResponse::HTTP_OK); } catch (Exception $e) { DB::rollBack(); return response()->json( ['message' => $e->getMessage()], JsonResponse::HTTP_INTERNAL_SERVER_ERROR ); } } public function update(EducationRequest $request, int $educationId) { try { $candidate = $request->talentBankUser; DB::beginTransaction(); $data = $request->all(); $education = $this->educationService->getByCustom([ ['column' => 'candidate_id', 'value' => $candidate->id], ['column' => 'id', 'value' => $educationId], ]); if ($education->count() == 0) { return response()->json( ['message' => __('crud.message.object_not_found', ['object' => __('crud.model.talent_bank.education')])], JsonResponse::HTTP_NOT_FOUND ); } $response = $this->educationService->update($data, $education->first()); DB::commit(); return response()->json([ 'message' => __('crud.message.update', ['model' => __('crud.model.talent_bank.education')]), 'education' => new EducationResource($response), ], JsonResponse::HTTP_OK); } catch (Exception $e) { DB::rollBack(); return response()->json( ['message' => $e->getMessage()], JsonResponse::HTTP_INTERNAL_SERVER_ERROR ); } } public function destroy(Request $request, int $educationId) { try { $candidate = $request->talentBankUser; DB::beginTransaction(); $education = $this->educationService->getByCustom([ ['column' => 'candidate_id', 'value' => $candidate->id], ['column' => 'id', 'value' => $educationId], ]); if ($education->count() == 0) { return response()->json( ['message' => __('crud.message.object_not_found', ['object' => __('crud.model.talent_bank.education')])], JsonResponse::HTTP_NOT_FOUND ); } $this->educationService->destroy($education->first()); DB::commit(); return response()->json([ 'message' => __('crud.message.delete', ['model' => __('crud.model.talent_bank.education')]), ], JsonResponse::HTTP_OK); } catch (Exception $e) { DB::rollBack(); return response()->json( ['message' => $e->getMessage()], JsonResponse::HTTP_INTERNAL_SERVER_ERROR ); } } }
| ver. 1.4 |
Github
|
.
| PHP 8.3.28 | Generation time: 0.02 |
proxy
|
phpinfo
|
Settings