|
|
@@ -0,0 +1,64 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace App\Http\Resources;
|
|
|
+
|
|
|
+use Carbon\Carbon;
|
|
|
+use Illuminate\Http\Request;
|
|
|
+use Illuminate\Http\Resources\Json\JsonResource;
|
|
|
+use Illuminate\Http\Resources\Json\AnonymousResourceCollection;
|
|
|
+use Illuminate\Support\Facades\Storage;
|
|
|
+use App\Models\UnitPartner;
|
|
|
+
|
|
|
+class UnitPartnerResource extends JsonResource
|
|
|
+{
|
|
|
+ public function toArray(Request $request): array
|
|
|
+ {
|
|
|
+ return [
|
|
|
+ 'id' => $this->id,
|
|
|
+ 'unit_id' => $this->unit_id,
|
|
|
+ 'name' => $this->name,
|
|
|
+ 'social_name' => $this->social_name,
|
|
|
+ 'role' => $this->role,
|
|
|
+ 'cpf' => $this->cpf,
|
|
|
+ 'rg' => $this->rg,
|
|
|
+ 'birth_date' => $this->birth_date?->format('Y-m-d'),
|
|
|
+ 'participation' => $this->participation,
|
|
|
+ 'email' => $this->email,
|
|
|
+ 'secondary_email' => $this->secondary_email,
|
|
|
+ 'phone_number' => $this->phone_number,
|
|
|
+ 'cell_number' => $this->cell_number,
|
|
|
+ 'postal_code' => $this->postal_code,
|
|
|
+ 'street' => $this->street,
|
|
|
+ 'address_number' => $this->address_number,
|
|
|
+ 'neighborhood' => $this->neighborhood,
|
|
|
+ 'complement' => $this->complement,
|
|
|
+ 'city_id' => $this->city_id,
|
|
|
+ 'state_id' => $this->state_id,
|
|
|
+ 'avatar_url' => $this->avatar_url
|
|
|
+ ? Storage::disk('public')->url($this->avatar_url)
|
|
|
+ : null,
|
|
|
+ 'created_at' => Carbon::parse($this->created_at)->format('Y-m-d H:i:s'),
|
|
|
+ 'updated_at' => Carbon::parse($this->updated_at)->format('Y-m-d H:i:s'),
|
|
|
+
|
|
|
+ 'city' => $this->whenLoaded('city', fn() => [
|
|
|
+ 'id' => $this->city->id,
|
|
|
+ 'name' => $this->city->name,
|
|
|
+ ]),
|
|
|
+
|
|
|
+ 'state' => $this->whenLoaded('state', fn() => [
|
|
|
+ 'id' => $this->state->id,
|
|
|
+ 'name' => $this->state->name,
|
|
|
+ 'code' => $this->state->code,
|
|
|
+ ]),
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param \Illuminate\Database\Eloquent\Collection<UnitPartner> $resource
|
|
|
+ * @return \Illuminate\Http\Resources\Json\AnonymousResourceCollection<UnitPartnerResource>
|
|
|
+ */
|
|
|
+ public static function collection($resource): AnonymousResourceCollection
|
|
|
+ {
|
|
|
+ return parent::collection($resource);
|
|
|
+ }
|
|
|
+}
|