| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- <?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::temporaryUrl($this->avatar_url, now()->addHours(24))
- : 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);
- }
- }
|