方法[validateRequire]不存在

时间:2016-07-07 03:12:48

标签: php validation laravel laravel-5.2

我正在进行数据验证,但它会抛出此错误:

 exception 'BadMethodCallException' with message 'Method [validateRequire] does not exist.' in G:\WEB\litraen\vendor\laravel\framework\src\Illuminate\Validation\Validator.php:3265

执行验证时。

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
              ]);
        }
    }

为什么显示此错误? 可能有错吗?

谢谢:)

3 个答案:

答案 0 :(得分:15)

解决方案:

'name' => 'required|max:25',
'email' => 'required|email|unique:users',
'password' => 'required|min:6'

缺少“d”

答案 1 :(得分:2)

我只是发布此信息,也许有人会遇到相同的错误。 U应将require更改为required,如下所示:

 'name' => 'required|max:25',
 'email' => 'required|email|unique:users',
 'password' => 'required|min:6'

答案 2 :(得分:0)

勾选验证“require”,改为“required”。 这应该允许它运行。