'array', 'nutritional_values' => 'array', ]; /** * The Laravel disk name * * @var string */ protected static $disk = 'inco'; /** * Storage path * * @var string */ protected static $imagesPath = 'images'; // * METHODS /** * Get xml inco picture path * * @param string $pictureName * @return null|string */ public static function getXmlIncoPicturePath(string $pictureName): ?string { $disk = static::getDisk(); $picturePath = static::$imagesPath . "/{$pictureName}"; return $disk->exists($picturePath) ? $picturePath : null; } /** * Getter media list retrieve a collection of medias * * @return \Illuminate\Support\Collection Indexes are filename and imgdata. */ public function getMediaListAttribute(): Collection { $disk = static::getDisk(); /** @var \Illuminate\Support\Collection */ $collFiles = new Collection(); foreach ($this->pictures as $pictureName) { $collFiles->add([ 'filename' => $pictureName, 'imgdata' => base64_encode($disk->get( static::$imagesPath . "/{$pictureName}" )) ]); } return $collFiles; } /** * Get the concerned disk * * @return \Illuminate\Contracts\Filesystem\Filesystem */ public static function getDisk(): Filesystem { return Storage::disk(static::$disk); } /** * Getter nice_string attribute * * @return string */ public function getNiceStringAttribute() { return sprintf('%s - %s', $this->id, $this->descriptif); } /** * Translate Data to compatible minicrud inputs for product * * @return array * @throws \RuntimeException If a product minicrud input is not handled for translation. */ public function translateToProductIncoInputs(): array { return \collect(DefaultProductType::incoInputs())->keys() ->mapWithKeys(function (string $key) { switch ($key) { case 'ingredients': return [$key => \strval($this->lst_ing)]; case 'preparation_advices': return [$key => \strval($this->conseil_prepa)]; case 'allergens': return [$key => \strval($this->lib_allergene)]; case 'selling_arguments': return [$key => \strval($this->arg_vente)]; case 'servings': return [$key => \strval($this->nb_portion)]; case 'servings_type': return [$key => \strval($this->typ_portion)]; default: throw new \RuntimeException('Unhandled product minicrud input'); } })->all(); } }