File: /mnt/data/ghayatcom/ghayatcom-api/app/Rules/Base64Image.php
<?php
namespace App\Rules;
use Illuminate\Contracts\Validation\Rule;
class Base64Image implements Rule
{
/**
* Create a new rule instance.
*
* @return void
*/
public function __construct()
{
//
}
/**
* Determine if the validation rule passes.
*
* @param string $attribute
* @param mixed $value
* @return bool
*/
public function passes($attribute, $value)
{
try {
$support_type = ['image/png', 'image/jpeg', 'image/jpg'];
$result = mime_content_type($value);
return in_array($result, $support_type);
} catch (\Exception $th) {
return false;
}
}
/**
* Get the validation error message.
*
* @return string
*/
public function message()
{
return ':attribute should be a Image and allowed .jpg, .jpeg, .png format';
}
}