File manager - Edit - /var/www/html/spdc/api/app/Http/Services/ShelterVoluntaryService.php
Back
<?php namespace App\Http\Services; use App\Classes\BaseServiceResponse; use App\Http\Requests\ShelterVoluntaryRequest; use App\Http\Resources\ShelterVoluntaryResource; use App\Models\Shelter; use App\Models\ShelterVoluntary; use Illuminate\Http\JsonResponse; class ShelterVoluntaryService extends BaseService { public function indexByShelter(string $shelterId): BaseServiceResponse { $shelter = Shelter::where('id', $shelterId)->first(); if (!$shelter) { return $this->response( ['message' => 'Shelter not found'], JsonResponse::HTTP_NOT_FOUND ); } $query = $shelter->shelterVoluntaries() ->where('is_active', true); $name = trim(request()->get('name')); if (!empty($name)) { $query->where('name', 'LIKE', '%' . $name . '%'); } $voluntaries = $query->paginate(15); return $this->response( ShelterVoluntaryResource::collection($voluntaries), JsonResponse::HTTP_OK ); } public function index(): BaseServiceResponse { $voluntaries = ShelterVoluntary::paginate(15); return $this->response( ShelterVoluntaryResource::collection($voluntaries), JsonResponse::HTTP_OK ); } public function show(string $id): BaseServiceResponse { $voluntary = ShelterVoluntary::findOrFail(['id' => $id])->first(); return $this->response( new ShelterVoluntaryResource($voluntary), JsonResponse::HTTP_OK ); } public function store(ShelterVoluntaryRequest $request): BaseServiceResponse { $data = $request->all(); $shelter = Shelter::find(["id" => $data['shelter_id']])->first(); $newVoluntary = new ShelterVoluntary(); $newVoluntary->name = $data['name']; $newVoluntary->city = $data['city']; $newVoluntary->state = $data['state']; $newVoluntary->street = $data['street']; $newVoluntary->zip_code = $data['zip_code']; $newVoluntary->neighborhood = $data['neighborhood']; $newVoluntary->number = $data['number']; $newVoluntary->specialties = $data['specialties']; $newVoluntary->observation = $data['observation']; $newVoluntary->shelter()->associate($shelter); $newVoluntary->is_active = true; $newVoluntary->cpf = $data['cpf']; $newVoluntary->created_by = $data['user']['id']; $newVoluntary->is_nupdec = false; $newVoluntary->phone = $data['phone']; $newVoluntary->save(); return $this->response( new ShelterVoluntaryResource($newVoluntary), JsonResponse::HTTP_CREATED ); } public function update(ShelterVoluntaryRequest $request, $id): BaseServiceResponse { $data = $request->all(); $voluntary = ShelterVoluntary::findOrFail(['id' => $id])->first(); $voluntary->name = $data['name']; $voluntary->city = $data['city']; $voluntary->state = $data['state']; $voluntary->street = $data['street']; $voluntary->zip_code = $data['zip_code']; $voluntary->neighborhood = $data['neighborhood']; $voluntary->number = $data['number']; $voluntary->specialties = $data['specialties']; $voluntary->observation = $data['observation']; $voluntary->is_active = $data['is_active']; $voluntary->cpf = $data['cpf']; $voluntary->phone = $data['phone']; $voluntary->save(); return $this->response( new ShelterVoluntaryResource($voluntary), JsonResponse::HTTP_CREATED ); } }
| ver. 1.4 |
Github
|
.
| PHP 8.3.28 | Generation time: 0.02 |
proxy
|
phpinfo
|
Settings