php 方法 [validateRequire] 不存在
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/38237024/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Method [validateRequire] does not exist
提问by Reco Jhonatan
I am making a data validation, but it throws this error:
我正在进行数据验证,但它会引发此错误:
exception 'BadMethodCallException' with message 'Method [validateRequire] does not exist.' in G:\WEB\litraen\vendor\laravel\framework\src\Illuminate\Validation\Validator.php:3265
when performing the validation.
在执行验证时。
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Validator;
use App\Http\Requests;
class UserController extends Controller
{
public function Register(Request $request){
$validator = Validator::make($request->all(),[
'name' => 'required|max:25',
'email' => 'require|email|unique:users',
'password' => 'require|min:6'
]);
if ($validator->fails()){
return response()->json([
'success' => false,
'errors' => $validator->errors()->toArray()
]);
}
return response()->json([
'success' => true
]);
}
}
why shows this error? that could have wrong?
为什么会显示这个错误?那可能有错吗?
Thank you :)
谢谢 :)
回答by Reco Jhonatan
SOLUTION:
解决方案:
'name' => 'required|max:25',
'email' => 'required|email|unique:users',
'password' => 'required|min:6'
lacked the "d"
缺少“d”
回答by Jose Pinto
I'm just posting this maybe someone will got the same error.
U should change require
to required
, as bellow:
我只是发布这个,也许有人会遇到同样的错误。你应该require
改为required
,如下所示:
'name' => 'required|max:25',
'email' => 'required|email|unique:users',
'password' => 'required|min:6'