| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- <?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\Unit;
- class UnitResource extends JsonResource
- {
- /**
- * Transform the resource into an array.
- *
- * @return array<string, mixed>
- */
- public function toArray(Request $request): array
- {
- return [
- 'id' => $this->id,
- 'fantasy_name' => $this->fantasy_name,
- 'social_reason' => $this->social_reason,
- 'cnpj' => $this->cnpj,
- 'state_registration' => $this->state_registration,
- 'name_responsible' => $this->name_responsible,
- 'street' => $this->street,
- 'address_number' => $this->address_number,
- 'postal_code' => $this->postal_code,
- 'neighborhood' => $this->neighborhood,
- 'complement' => $this->complement,
- 'city_id' => $this->city_id,
- 'state_id' => $this->state_id,
- 'email' => $this->email,
- 'secondary_email' => $this->secondary_email,
- 'phone_number' => $this->phone_number,
- 'cell_number' => $this->cell_number,
- '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<Unit> $resource
- * @return \Illuminate\Http\Resources\Json\AnonymousResourceCollection<UnitResource>
- */
- public static function collection($resource): AnonymousResourceCollection
- {
- return parent::collection($resource);
- }
- }
|