| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- <?php
- namespace App\Http\Resources;
- use Carbon\Carbon;
- use Illuminate\Http\Request;
- use Illuminate\Http\Resources\Json\JsonResource;
- use App\Http\Resources\MediaResource;
- class PartnerAgreementResource extends JsonResource
- {
- public function toArray(Request $request): array
- {
- return [
- 'id' => $this->id,
- 'user_id' => $this->user_id,
- 'user' => $this->whenLoaded('user', fn() => $this->user ? ['id' => $this->user->id, 'name' => $this->user->name] : null),
- 'company_name' => $this->company_name,
- 'cnpj' => $this->cnpj,
- 'category_id' => $this->category_id,
- 'category' => $this->whenLoaded('category', fn() => new CategoryResource($this->category)),
- 'responsible' => $this->responsible,
- 'discount_percentage' => $this->discount_percentage,
- 'description' => $this->description,
- 'email' => $this->email,
- 'phone' => $this->phone,
- 'whatsapp' => $this->whatsapp,
- 'website' => $this->website,
- 'address' => $this->address,
- 'neighborhood' => $this->neighborhood,
- 'city_id' => $this->city_id,
- 'city' => $this->whenLoaded('city', fn() => new CityResource($this->city)),
- 'state_id' => $this->state_id,
- 'state' => $this->whenLoaded('state', fn() => new StateResource($this->state)),
- 'zip_code' => $this->zip_code,
- 'working_hours' => $this->working_hours,
- 'contract_start' => $this->contract_start?->format('Y-m-d'),
- 'contract_end' => $this->contract_end?->format('Y-m-d'),
- 'status' => $this->status,
- 'logo' => $this->whenLoaded('logo', fn() => $this->logo ? new MediaResource($this->logo) : null),
- 'media' => $this->whenLoaded('media', fn() => MediaResource::collection($this->media)),
- 'services' => $this->whenLoaded('services', fn() => PartnerAgreementServiceResource::collection($this->services)),
- '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'),
- ];
- }
- }
|