2020-04-26 19:09:43 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Rules;
|
|
|
|
|
|
|
|
use Illuminate\Contracts\Validation\Rule;
|
2024-01-10 00:47:09 +00:00
|
|
|
use Illuminate\Support\Str;
|
2020-04-26 19:09:43 +00:00
|
|
|
|
|
|
|
class ImageData implements Rule
|
|
|
|
{
|
|
|
|
public function passes($attribute, $value): bool
|
|
|
|
{
|
2022-08-08 16:00:59 +00:00
|
|
|
return attempt(static function () use ($value) {
|
2024-01-10 00:47:09 +00:00
|
|
|
return (bool) preg_match('/data:image\/(jpe?g|png|webp|gif)/i', Str::before($value, ';'));
|
2022-08-08 16:00:59 +00:00
|
|
|
}, false) ?? false;
|
2020-04-26 19:09:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function message(): string
|
|
|
|
{
|
|
|
|
return 'Invalid DataURL string';
|
|
|
|
}
|
|
|
|
}
|