1234567891011121314151617181920212223242526272829303132333435363738394041 |
- <?php
- namespace App\Http\Resources\API;
- 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
- {
- return [
- 'id' => $this->id,
- 'name' => $this->name,
- 'code' => $this->code,
- 'description' => $this->description,
- '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' => $this->whitelist,
- 'latitude' => $this->latitude,
- 'longitude' => $this->longitude,
- 'parent_id' => $this->parent_id,
- 'level' => count(explode(",", trim($this->path, ","))),
- 'children' => $this->when($this->children->isNotEmpty(), function () {
- return $this->children->map(function ($child) {
- return new AssetResource($child, $this->level);
- })->all();
- }),
- ];
- }
- }
|