getCategories(), consumptionTimes: $this->getConsumptionTimes(), inspirations: $this->getInspirations(), seasons: $this->getSeasons(), search: $this->getSearchValue() ?? '', ); } /** @return \Domain\Models\ValueObjects\Products\ProductCategory[] */ public function getCategories(): array { return array_map( function ($category) { if (! is_string($category)) { throw new \InvalidArgumentException('Category must be a string'); } return ProductCategory::from($category); }, $this->array('category'), ); } /** @return \Domain\Models\ValueObjects\Recipes\ConsumptionTime[] */ public function getConsumptionTimes(): array { return array_map( function ($time) { if (! is_string($time)) { throw new \InvalidArgumentException('Consumption time must be a string'); } return ConsumptionTime::from($time); }, $this->array('consumption_time'), ); } /** @return \Domain\Models\ValueObjects\Recipes\Inspiration[] */ public function getInspirations(): array { return array_map( function ($inspiration) { if (! is_string($inspiration)) { throw new \InvalidArgumentException('Inspiration must be a string'); } return Inspiration::from($inspiration); }, $this->array('inspiration'), ); } /** @return \Domain\Models\ValueObjects\Recipes\Season[] */ public function getSeasons(): array { return array_map( function ($season) { if (! is_string($season)) { throw new \InvalidArgumentException('Season must be a string'); } return Season::from($season); }, $this->array('season'), ); } public function getSearchValue(): ?string { return $this->has('search') && ! empty($this->string('search')->value()) ? $this->string('search')->value() : null; } /** * Get the validation rules that apply to the request. * * @return array|string> */ public function rules(): array { return [ 'search' => ['nullable', 'string'], 'category' => ['nullable', 'array'], 'category.*' => ['string'], 'consumption_time' => ['nullable', 'array'], 'consumption_time.*' => ['string'], 'inspiration' => ['nullable', 'array'], 'inspiration.*' => ['string'], 'season' => ['nullable', 'array'], 'season.*' => ['string'], ]; } }