diff --git a/src/Rules/MediaRule.php b/src/Rules/MediaRule.php index 86a5c46..f70f7b8 100644 --- a/src/Rules/MediaRule.php +++ b/src/Rules/MediaRule.php @@ -39,7 +39,7 @@ public function __construct(...$types) */ public function passes($attribute, $value) { - if (! $value instanceof UploadedFile) { + if (! $value instanceof UploadedFile && ! $this->isBase64($value)) { return false; } @@ -68,6 +68,10 @@ public function message() */ protected function getTypeString($value): string { + if ($this->isBase64($value)) { + return 'image'; + } + $fileFullPath = $value->getRealPath(); if ((new Image())->canHandleMime($value->getMimeType())) { @@ -80,10 +84,6 @@ protected function getTypeString($value): string ))); } - if (is_string($value) && base64_decode(base64_encode($value)) === $value) { - $type = 'image'; - } - return $type; // either: image, video or audio. } @@ -96,4 +96,15 @@ protected function documentsMimeTypes() { return Config::get('laravel-media-uploader.documents_mime_types'); } + + /** + * Determine whither the value is base64 image. + * + * @param $value + * @return bool + */ + protected function isBase64($value) + { + return is_string($value) && base64_decode(base64_encode($value)) === $value; + } }