Laravel 5.2 Validator :: Make抛出异常'参数2传递给Illuminate \ Validation \ Factory :: make()必须是类型数组,对象给出'

时间:2016-09-02 13:52:39

标签: php laravel laravel-5.2 laravel-validation laravel-spark

我一直使用laravel的自定义验证获取此异常,我不知道为什么。 以下是完整的异常消息:

local.ERROR: exception 'ErrorException' with message 'Argument 2 passed to Illuminate\Validation\Factory::make() must be of the type array, object given, called in /home/vagrant/Code/Spark/my-project/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php on line 223 and defined' in /home/vagrant/Code/Spark/my-project/vendor/laravel/framework/src/Illuminate/Validation/Factory.php:91

这是我的代码:

$rules = array(
        'name' => 'required|max:255',
        'email' => 'required|email|max:255|unique:users',
        'password' => 'required|confirmed|min:6',
        'vat_id' => 'max:50|vat_id',
        'terms' => 'required|accepted',
        'address' => 'required|max:255',
        'city' => 'required|max:255',
        'state' => 'required',
        'contactName' => 'required',
        'phone' => 'numeric|required',
        'zip' => 'numeric|required',
    );

    $validator = Validator::make($request->all(), $rules);

现在,我也尝试了这样,我得到了同样的例外:

    $validator = Validator::make($request->all(), [
        'name' => 'required|max:255',
        'email' => 'required|email|max:255|unique:users',
        'password' => 'required|confirmed|min:6',
        'vat_id' => 'max:50|vat_id',
        'terms' => 'required|accepted',
        'address' => 'required|max:255',
        'city' => 'required|max:255',
        'state' => 'required',
        'contactName' => 'required',
        'phone' => 'numeric|required',
        'zip' => 'numeric|required',
]);

据我所知,我正在完全遵循文档(https://www.laravel.com/docs/5.2/validation#manually-creating-validators),并传递数组。我在laravel中手动创建了很多次验证,从未遇到过这个问题。我希望有一些显而易见的事情,我做错了,也许另一组眼睛很容易接受,因为这让我非常难过。任何帮助非常感谢!如果它有所作为,我正在使用Spark。

编辑:这是我在var_dump $规则时获得的内容:

array (size=12)
'name' => string 'required|max:255' (length=16)
'email' => string 'required|email|max:255|unique:users' (length=35)
'password' => string 'required|confirmed|min:6' (length=24)
'vat_id' => string 'max:50|vat_id' (length=13)
'terms' => string 'required|accepted' (length=17)
'address' => string 'required|max:255' (length=16)
'city' => string 'required|max:255' (length=16)
'state' => string 'required' (length=8)
'contactName' => string 'required' (length=8)
'phone' => string 'numeric|required' (length=16)
'zip' => string 'numeric|required' (length=16)

0 个答案:

没有答案