File manager - Edit - /var/www/html/spdc/api/app/Http/Services/ShelterHistoricService.php
Back
<?php namespace App\Http\Services; use App\Classes\BaseServiceResponse; use App\Enums\TypeOfHistoricEnum; use App\Http\Requests\ShelterHistoricRequest; use App\Http\Resources\ShelterHistoricResource; use App\Models\Shelter; use App\Models\ShelterHistoric; use App\Models\ShelterManager; use Carbon\Carbon; use Illuminate\Http\JsonResponse; class ShelterHistoricService extends BaseService { public function historicsByShelter(string $id): BaseServiceResponse { $shelter = Shelter::findOrFail($id)->first(); return $this->response( [$shelter->shelterHistorics], JsonResponse::HTTP_OK ); } public function store(ShelterHistoricRequest $request): BaseServiceResponse { $data = $request->all(); $historic = $this->createHistoric($data); return $this->response( new ShelterHistoricResource($historic), JsonResponse::HTTP_OK ); } public function show(string $id) : BaseServiceResponse { $historic = ShelterHistoric::findOrFail($id)->first(); return $this->response( new ShelterHistoricResource($historic), JsonResponse::HTTP_OK ); } public function getTypes() { return $this->response(['status' => TypeOfHistoricEnum::cases()]); } public function createHistoric(array $data): ShelterHistoric { $shelter = Shelter::findOrFail(['id' => $data['shelter_id']])->first(); if (isset($data['manager_id'])) { $manager = ShelterManager::findOrFail(['id' => $data['manager_id']])->first(); } $carbonDate = Carbon::parse($data['date'])->format('Y-m-d H:i:s'); $historic = new ShelterHistoric(); $historic->type = $data['type']; $historic->created_by = $data['user']['id']; $historic->date=$carbonDate; if (isset($data['manager_id'])) { $historic->manager()->associate($manager); } if (isset($data['observation'])) { $historic->observation = $data['observation']; } $historic->shelter()->associate($shelter); $historic->save(); return $historic; } }
| ver. 1.4 |
Github
|
.
| PHP 8.3.28 | Generation time: 0.02 |
proxy
|
phpinfo
|
Settings