File manager - Edit - /var/www/html/spdc/api/app/Http/Controllers/ShelterController.php
Back
<?php namespace App\Http\Controllers; use App\Http\Requests\CloseShelterRequest; use App\Http\Requests\ConvertIntoShelterRequest; use App\Http\Requests\ConvertIntoSuportPointRequest; use App\Http\Requests\OpenShelterRequest; use App\Http\Requests\ShelterRealOpenRequest; use App\Http\Requests\ShelterRequest; use App\Http\Services\ShelterService; use App\Models\Shelter; use App\Models\ShelterFamily; use App\Models\ShelterMemberFamily; use Illuminate\Http\JsonResponse; use Illuminate\Support\Facades\Response; class ShelterController extends Controller { private ShelterService $service; public function __construct() { $this->service = new ShelterService(); } public function index() { $response = $this->service->index(); return response()->json($response->data, $response->code); } public function showDashboard(string $id) { $response = $this->service->showDashboard($id); return response()->json($response->data, $response->code); } public function show(string $id) { $response = $this->service->show($id); return response()->json($response->data, $response->code); } public function store(ShelterRequest $request) { $response = $this->service->store($request); return response()->json($response->data, $response->code); } public function update(ShelterRequest $request, string $id) { $response = $this->service->update($request, $id); return response()->json($response->data, $response->code); } public function openShelter(OpenShelterRequest $request) { $response = $this->service->openShelter($request); return response()->json($response->data, $response->code); } public function closeShelter(CloseShelterRequest $request) { $response = $this->service->closeShelter($request); return response()->json($response->data, $response->code); } public function getAreaTypes() { $response = $this->service->getAreaTypes(); return response()->json($response->data, $response->code); } public function setRealOpenDate(ShelterRealOpenRequest $request) { $response = $this->service->setRealOpenDate($request); return response()->json($response->data, $response->code); } public function convertIntoShelter(ConvertIntoShelterRequest $request) { $response = $this->service->convertIntoShelter($request); return response()->json($response->data, $response->code); } public function convertIntoSuportPoint(ConvertIntoSuportPointRequest $request) { $response = $this->service->convertIntoSuportPoint($request); return response()->json($response->data, $response->code); } public function generateReport(string $id) { $families = ShelterFamily::where(['shelter_id' => $id])->get(); $csvFileName = 'shelter.csv'; $headers = array( "Content-type" => "text/csv", "Content-Disposition" => "attachment; filename=$csvFileName", "Pragma" => "no-cache", "Cache-Control" => "must-revalidate, post-check=0, pre-check=0", "Expires" => "0" ); $handle = fopen('php://output', 'w'); fputcsv($handle, array('Nome', 'Idade', 'Documento')); foreach($families as $family) { $members = $family->members->toArray(); foreach($members as $member) { if($member['is_sheltered'] || $member['last_shelter_id'] == $id) { fputcsv($handle, array($member['name'], $member['age'], $member['document'])); } } } fclose($handle); return Response::make(file_get_contents('php://output'), 200, $headers); } public function getShelteredFamilies(string $id) { $response = $this->service->getShelteredFamilies($id); return response()->json($response->data, $response->code); } }
| ver. 1.4 |
Github
|
.
| PHP 8.3.28 | Generation time: 0.01 |
proxy
|
phpinfo
|
Settings