Skip to content

Instantly share code, notes, and snippets.

@fntneves
Last active December 24, 2015 22:30
Show Gist options
  • Save fntneves/3f0c260de1aa9399236e to your computer and use it in GitHub Desktop.
Save fntneves/3f0c260de1aa9399236e to your computer and use it in GitHub Desktop.
Validator extension for Image Data URI
<?php
Validator::extend('image_uri', function($attribute, $value, $parameters, $validator) {
$matches = [];
$pattern = '/^data:image\/(jpe?g|png|bmp|gif|svg);base64\,.+$/';
return preg_match($pattern, $value, $matches) > 0 && in_array($matches[1], $parameters);
});
@fntneves
Copy link
Author

Usage:

Validator::make($request->all(), [
    'picture' => 'image_uri:png,jpg'
]);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment