data = collect(json_decode(file_get_contents($file), true)['data']); Cache::put('items', $this->data); } else { $this->data = Cache::get('items'); } } /** * @param string $query * @return Collection */ public function findItem(string $query): Collection { return $this->data->filter(function ($val) use ($query) { $query = Str::lower($query); return Str::contains($val['_id'], $query) || Str::contains($val['_name'], $query) || Str::contains($val['_parent'], $query); })->map(function ($item) { return [ '_id' => $item['_id'], '_name' => $item['_name'], ]; })->values(); } /** * @param string $id * @return array * @throws ItemNotFoundException */ public function getItemById(string $id): array { return $this->data[$id] ?? throw new ItemNotFoundException('Item not found'); } }