Laravel Validator由于数组到字符串的转换而失败


Laravel Validator fails due to array to string conversion

我正在尝试验证此输入:

$values = [                                                
    'id'                => $input['id'][$i],   
    'template_id'       => $input['template_id'][$i],   
    'schedulable_id'    => $id,                               
    'schedulable_type'  => $type,       
    'order_by'          => $i                                 
];

在我的时间表类中发现了这些规则:

public static $rules = [                                                                                         
    'template_id'           => 'required|integer|exists:templates,id',                                        
    'schedulable_id'        => 'required|integer',                                                                  
    'schedulable_type'      => 'required|in:Item,Order',
    'order_by'              => 'integer'                                                                            
];

当我执行以下操作时,我总是在第905:行的"/lavel/vendor/lavel/framework/src/IIlluminate/Validation/Validator.php"中得到一个数组到字符串的转换错误

$validator = Validator::make($values, Schedule::$rules);
if ($validator->fails()) {
    $errors[$i] = $validator->messages();
    continue;
}

为什么会发生这种情况?

刚刚发现我有Ardent的$forceEntityHydrationFromInput = true,由于我的输入是作为部分引用值的数组提交的,因此无法直接从Input中提取以进行验证。

要解决这个问题,请更改为$forceEntityHydrationFromInput = false并使用标准的输入验证过程,而不是依赖Ardent的魔术。

有时候聪明的包装太聪明了。