id : false; } public static function getBySlug($slug) { return ArticleNature::bySlug($slug)->first(); } public static function getProductTypeBySlug($slug) { $id = self::getIdBySlug($slug); return $id ? self::getProductType($id) : false; } public static function storeIcon($nature, $file, $collection = 'images') { Medias::deleteImages($nature, $collection); return $file ? Medias::storeImage($nature, $file, $collection) : false; } public static function getProductType($id) { $model = self::get($id); $type = $model ? $model->product_type : false; return $type ? self::getProductTypes()[$type] : false; } public static function getProductTypeNameByClass($model) { return self::getProductTypeName(self::getProductTypeByModel($model)); } public static function getProductTypeName($type) { return self::getProductTypes()[$type] ?? false; } public static function getProductTypeByModel($model) { switch ($model) { case Specie::class: case Variety::class: $type = 1; break; case Merchandise::class: $type = 2; break; default: $type = false; } return $type; } public static function getProductTypes() { return ['', 'botanic', 'merchandise']; } public static function getOptionsByBotanic() { return self::getOptionsByProductType(1); } public static function getOptionsByMerchandise() { return self::getOptionsByProductType(2); } public static function getOptionsByProductTypeModel($model) { $type = self::getProductTypeByModel($model); return self::getOptionsByProductType($type); } public static function getOptionsByProductType($type) { return self::getByProductType($type)->pluck('name', 'id')->toArray(); } public static function getByProductType($type) { return ArticleNature::byProductType($type)->get(); } public static function getByCategory($categoryId) { return Article::byCategory($categoryId)->select('article_nature_id')->distinct()->get(); } public static function getNamesByIds($ids) { $names = ArticleNature::byIds($ids)->pluck('name')->toArray(); return array_map('strtolower', $names); } public static function getModel() { return ArticleNature::query(); } }