*/ public function toArray(Request $request): array { $maxLimits = 2; $maxApplies = 3; return [ 'vnum' => $this->vnum, 'name' => $this->locale_name, 'type' => $this->type->getLabel(), 'subtype' => $this->subtype, // 'refined_vnum', 'refine_set' => new ItemProtoRefineResource($this->refineSet), 'magic_pct' => $this->magic_pct, // Limits 'limits' => collect(range(0, $maxLimits - 1)) ->map(fn ($index) => [ 'type' => $this->{"limittype$index"}, 'value' => $this->{"limitvalue$index"}, ]) ->filter(fn ($row) => $row['type']->value !== 0) ->map(fn ($row) => ['type' => $row['type']->getLabel(), 'value' => $row['value']]), // Applies 'applies' => collect(range(0, $maxApplies - 1)) ->map(fn ($index) => [ 'type' => $this->{"applytype$index"}, 'value' => $this->{"applyvalue$index"}, ]) ->filter(fn ($row) => $row['type']->value !== 0) ->map(fn ($row) => ['type' => $row['type']->getLabel(), 'value' => $row['value']]), ]; } }