我正在尝试在laravel 5.3中创建自定义验证规则。在 AppServiceProvider 中,我像这样扩展了Validator
Validator::extend('image64',function ($attribute,$value,$parameters,$validator){
$type = explode(',',$value)[0];
if (stripos($type, "image/jpeg") !== false || stripos($type, "image/jpg") !== false || stripos($type, "image/jpeg") !== false) {
return true;
}
return false;
});
并在 validation.php
内'custom' => [
'base64' => 'The :attribute must be an jpeg/jpg/png',
'attribute-name' => [
'rule-name' => 'custom-message',
],
],
我正在我的控制器中使用它。
$validator = Validator::make($request->all(), [
'name' => 'required|max:255|unique:industries',
'image' => 'required|base64'
]);
但我收到错误
"Method [validateBase64] does not exist."