diff --git a/src/Enums/SpatieMediaMethodEnum.php b/src/Enums/SpatieMediaMethodEnum.php index edfb434..9b1c321 100644 --- a/src/Enums/SpatieMediaMethodEnum.php +++ b/src/Enums/SpatieMediaMethodEnum.php @@ -8,9 +8,17 @@ enum SpatieMediaMethodEnum: string { use LazyEnum; - case addMediaFromString = 'addMediaFromString'; + case addMedia = 'addMedia'; case addMediaFromBase64 = 'addMediaFromBase64'; case addMediaFromDisk = 'addMediaFromDisk'; + + case addMediaFromRequest = 'addMediaFromRequest'; + + case addMediaFromStream = 'addMediaFromStream'; + + case addMediaFromString = 'addMediaFromString'; + + case addMediaFromUrl = 'addMediaFromUrl'; } diff --git a/src/Services/MediaService.php b/src/Services/MediaService.php index 380c213..ee6c4d4 100644 --- a/src/Services/MediaService.php +++ b/src/Services/MediaService.php @@ -11,6 +11,8 @@ /** * MediaService to manage media files. * + * @deprecated Use Kiwilan\Steward\Utils\SpatieMedia instead. + * * @property Model $model * @property string $name * @property string|UnitEnum $disk diff --git a/src/Utils/SpatieMedia.php b/src/Utils/SpatieMedia.php new file mode 100644 index 0000000..c4b65ae --- /dev/null +++ b/src/Utils/SpatieMedia.php @@ -0,0 +1,118 @@ +model->{$this->method->value}($data) + ->setName($this->name) + ->setFileName($this->name.'.'.$this->extension) + ->toMediaCollection($this->collection, $this->disk) + ; + $this->model->refresh(); + } + + return $this; + } + + public function setColor(): self + { + // @phpstan-ignore-next-line + $image = $this->model->getFirstMediaPath($this->collection); + + if ($image) { + $color = Picture::color($image); + // @phpstan-ignore-next-line + $media = $this->model->getFirstMedia($this->collection); + $media->setCustomProperty('color', $color); + $media->save(); + } + + return $this; + } + + public static function getFullUrl(Model $model, string $collection, ?string $conversion = ''): string + { + $cover = null; + + try { + // @phpstan-ignore-next-line + $cover = $model->getFirstMediaUrl($collection, $conversion); + } catch (\Throwable $th) { + } + + return $cover ? $cover : config('app.url').'/vendor/vendor/images/no-cover.webp'; + } +}