File manager - Edit - /var/www/html/spdc/api/app/Http/Services/OccurrencyScriptureInterdictionService.php
Back
<?php namespace App\Http\Services; use PDF; use App\Models\Occurrency; use Illuminate\Support\Carbon; use Illuminate\Http\JsonResponse; use App\Classes\BaseServiceResponse; use Illuminate\Support\Facades\Storage; use App\Models\OccurrencyScriptureInterdiction; use App\Http\Requests\OccurrencyScriptureInterdictionRequest; use App\Http\Resources\OccurrencyScriptureInterdictionResource; class OccurrencyScriptureInterdictionService extends BaseService { public function store(OccurrencyScriptureInterdictionRequest $request, Occurrency $occurrency): BaseServiceResponse { if (!in_array('AUTOS', $occurrency->category?->sections)) { $this->response(null, JsonResponse::HTTP_BAD_REQUEST, 'This occurrency can not have scriptures.'); } $inputs = $request->all(); $user = $request->user; $scripture = $occurrency->scriptures()->create([ ...$inputs, 'responsable' => [ 'name' => $user['name'], 'document' => $user['document'], 'registration' => $user['registration'], 'email' => $user['email'] ] ]); $interdiction = $scripture->interdictions()->create($inputs); return $this->response(new OccurrencyScriptureInterdictionResource($interdiction), JsonResponse::HTTP_CREATED); } public function update(OccurrencyScriptureInterdictionRequest $request, OccurrencyScriptureInterdiction $interdiction): BaseServiceResponse { $inputs = $request->all(); $interdiction->scripture->fill($inputs)->save(); $interdiction->fill($inputs)->save(); return $this->response(new OccurrencyScriptureInterdictionResource($interdiction)); } public function show(OccurrencyScriptureInterdiction $interdiction): BaseServiceResponse { return $this->response(new OccurrencyScriptureInterdictionResource($interdiction)); } public function pdf(OccurrencyScriptureInterdiction $interdiction): BaseServiceResponse { $scripture = $interdiction->scripture; $address = $scripture->occurrency?->address?->setAppends(['full_address']); $occurrency = $interdiction->scripture?->occurrency; $signature = $interdiction->scripture?->signature; Carbon::setLocale('pt_BR'); $date = Carbon::now()->isoFormat('D [de] MMMM [de] YYYY'); $signature_date = $signature?->created_at?->isoFormat('D [de] MMMM [de] YYYY'); // generating pdf $data = [ 'ban_type' => $interdiction?->ban_type, 'place' => $interdiction?->scripture?->placeType->name, 'address' => $address?->full_address, 'occurrency_code' => $occurrency?->code, 'implementation_type' => $interdiction?->implementation_type, 'area' => $interdiction?->area, 'date' => $date, 'responsable_name' => $scripture?->responsable['name'], 'responsable_registration' => $scripture?->responsable['registration'], 'notes' => $scripture?->note, 'base64Signature' => $signature?->file, 'signature_name' => $signature?->name, 'signature_document' => $signature?->document, 'signature_date' => $signature_date, 'family_composition' => $interdiction->family_composition ]; $pdf = PDF::loadView('scriptures.interdiction', $data); $pdf->setOption('chroot',public_path('/')); $pdfContent = $pdf->output(); // Storage::put(storage_path('temp/' . str()->uuid() . '.pdf'), $pdfContent); // convert to base64 $base64pdf = base64_encode($pdfContent); // saving $interdiction->scripture?->fill(['file' => $base64pdf])->save(); return $this->response(new OccurrencyScriptureInterdictionResource($interdiction)); } }
| ver. 1.4 |
Github
|
.
| PHP 8.3.28 | Generation time: 0.02 |
proxy
|
phpinfo
|
Settings