我正在尝试验证此输入:
I'm trying to validate this input:
$values = [ 'id' => $input['id'][$i], 'template_id' => $input['template_id'][$i], 'schedulable_id' => $id, 'schedulable_type' => $type, 'order_by' => $i ];针对我的Schedule类中的这些规则:
Against these rules found in my Schedule class:
public static $rules = [ 'template_id' => 'required|integer|exists:templates,id', 'schedulable_id' => 'required|integer', 'schedulable_type' => 'required|in:Item,Order', 'order_by' => 'integer' ];执行以下操作时,总是在第905行的"/laravel/vendor/laravel/framework/src/Illuminate/Validation/Validator.php"中出现数组到字符串的转换错误:
When I do the following, I always get an array to string conversion error in "/laravel/vendor/laravel/framework/src/Illuminate/Validation/Validator.php" on line 905:
$validator = Validator::make($values, Schedule::$rules); if ($validator->fails()) { $errors[$i] = $validator->messages(); continue; }为什么会这样?
推荐答案刚刚发现我有Ardent的$forceEntityHydrationFromInput = true,并且由于将其作为数组提交的事实而无法直接从Input提取我的输入以进行验证部分引用的值.
Just discovered I had Ardent's $forceEntityHydrationFromInput = true and my input cannot be pulled directly from Input for validation purposes due to the fact that it is submitted as an array of partially referenced values.
要解决此问题,请更改为$forceEntityHydrationFromInput = false并使用标准输入验证过程,而不要依赖Ardent的魔力.
To fix this, change to $forceEntityHydrationFromInput = false and use standard input validation procedure instead of relying on Ardent's magic.
有时候聪明的软件包太聪明了.
Sometimes clever packages are too clever.
更多推荐
Laravel验证程序由于数组到字符串的转换而失败
发布评论