| 123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- <?php
- namespace App\Http\Resources;
- use Carbon\Carbon;
- use Illuminate\Http\Request;
- use Illuminate\Http\Resources\Json\JsonResource;
- use Illuminate\Support\Facades\Storage;
- class UserDependentResource extends JsonResource
- {
- public function toArray(Request $request): array
- {
- return [
- 'id' => $this->id,
- 'responsible_user_id' => $this->responsible_user_id,
- 'name' => $this->name,
- 'kinship' => $this->kinship,
- 'status' => $this->status,
- 'document_name' => $this->document_name,
- 'document_is_image' => $this->document_path
- ? in_array(
- strtolower(pathinfo($this->document_path, PATHINFO_EXTENSION)),
- ['jpg', 'jpeg', 'png', 'webp'],
- true,
- )
- : false,
- 'document_url' => $this->document_path
- ? Storage::disk('s3')->temporaryUrl($this->document_path, now()->addHours(24))
- : null,
- 'responsible_user' => $this->whenLoaded('responsibleUser', fn() => [
- 'id' => $this->responsibleUser->id,
- 'name' => $this->responsibleUser->name,
- 'position' => $this->responsibleUser->relationLoaded('position')
- ? $this->responsibleUser->position?->name
- : null,
- 'sector' => $this->responsibleUser->relationLoaded('sector')
- ? $this->responsibleUser->sector?->name
- : 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'),
- ];
- }
- }
|