File manager - Edit - /var/www/html/spdc/api/app/Http/Services/ShelterServiceAreaService.php
Back
<?php namespace App\Http\Services; use App\Classes\BaseServiceResponse; use App\Http\Requests\ShelterServiceAreaRequest; use App\Http\Resources\ShelterServiceAreaResource; use App\Models\Shelter; use App\Models\ShelterServiceArea; use Illuminate\Http\JsonResponse; class ShelterServiceAreaService extends BaseService { public function index(): BaseServiceResponse { $area = ShelterServiceArea::all(); return $this->response( ShelterServiceAreaResource::collection($area), JsonResponse::HTTP_OK ); } public function store(ShelterServiceAreaRequest $request): BaseServiceResponse { $data = $request->all(); $shelter = Shelter::find(['id' => $data['shelter_id']])->first(); $area = new ShelterServiceArea(); $area->type = $data['type']; $area->name = $data['name']; $area->washing_tank_amount = $data['washing_tank_amount']; $area->washing_machine_amount = $data['washing_machine_amount']; $area->observation = array_key_exists('observation', $data) ? $data['observation'] : null; $area->shelter()->associate($shelter); $area->save(); return $this->response( new ShelterServiceAreaResource($area), JsonResponse::HTTP_CREATED ); } public function show($id): BaseServiceResponse { $area = ShelterServiceArea::findOrFail($id)->first(); return $this->response( new ShelterServiceAreaResource($area), JsonResponse::HTTP_OK ); } public function update(ShelterServiceAreaRequest $request, string $id) { $data = $request->all(); $oldArea = ShelterServiceArea::findOrFail($id)->first(); $oldArea->type = $data['type']; $oldArea->name = $data['name']; $oldArea->washing_tank_amount = $data['washing_tank_amount']; $oldArea->washing_machine_amount = $data['washing_machine_amount']; $oldArea->observation = array_key_exists('observation', $data) ? $data['observation'] : null; $oldArea->update(); return $this->response( new ShelterServiceAreaResource($oldArea), JsonResponse::HTTP_OK ); } public function destroy(string $id) { $area = ShelterServiceArea::findOrFail(['id' => $id])->first(); $area->delete(); return $this->response( [], JsonResponse::HTTP_OK ); } }
| ver. 1.4 |
Github
|
.
| PHP 8.3.28 | Generation time: 0.01 |
proxy
|
phpinfo
|
Settings