1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- <?php
- namespace App\Http\Resources\API;
- use App\Models\User;
- use App\Services\File\ImageUrlService;
- use Illuminate\Http\Request;
- use Illuminate\Http\Resources\Json\JsonResource;
- class AssetResource extends JsonResource
- {
- /**
- * Transform the resource into an array.
- *
- * @return array<string, mixed>
- */
- public function toArray(Request $request): array
- {
- $whitelist=make_array_list($this->whitelist??'');
- $whitelistName=User::query()->whereIn('id',$whitelist)->get();
- return [
- 'id' => $this->id,
- 'name' => $this->name,
- 'code' => $this->code,
- 'description' => $this->description?(new \App\Services\File\ImageUrlService)->getImageUrl($this->description):null,
- 'status' => $this->status,
- 'created_by' => $this->created_by,
- 'owner' => $this->owner,
- 'address' => $this->address,
- 'group_id' => $this->group_id ?? 0,
- 'geo_address_code' => $this->geo_address_code,
- 'acl' => $this->acl,
- 'whitelist' => $whitelist,
- 'whitelist_name' => UserProfileResource::collection($whitelistName),
- 'latitude' => $this->latitude,
- 'longitude' => $this->longitude,
- 'parent_id' => $this->parent_id,
- 'parent_asset' => $this->when($this->parent !== null, function () {
- return[
- new AssetParentResource($this->parent)
- ];
- }),
- 'level' => count(explode(",", trim($this->path, ","))),
- 'requirement_total' => $this->total_requirements_count,
- 'plan_total' => $this->total_plans_count,
- 'created_at'=> $this->created_at,
- 'equity_interest'=>$this->equity_interest,
- 'developer' =>$this->developer,
- 'date_completed' =>$this->date_completed,
- 'total_floor_area' => $this->total_floor_area,
- 'contact_person'=>$this->contact_person,
- 'contact_phone'=>$this->contact_phone,
- 'contact_email'=>$this->contact_email,
- 'property'=> $this->property,
- 'building_type_description'=>$this->building_type_description,
- 'children' => $this->when($this->children->isNotEmpty(), function () {
- return $this->children->map(function ($child) {
- return new AssetResource($child, $this->level);
- })->all();
- }),
- 'area_unit'=>$this->area_unit,
- 'project_total' => $this->projects()->count(),
- 'create_by_name'=>new UserProfileResource($this->createdBy),
- 'owner_by_name' => new UserProfileResource($this->byOwner),
- // 'whitelist_department'=>$this->whitelist_department,
- // 'whitelist_user'=>$this->whitelist_user,
- ];
- }
- }
|