Laravel验证程序由于数组到字符串的转换而失败

编程入门 行业动态 更新时间:2024-10-26 10:30:33
本文介绍了Laravel验证程序由于数组到字符串的转换而失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试验证此输入:

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验证程序由于数组到字符串的转换而失败

本文发布于:2023-10-13 17:14:21,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1488591.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数组   字符串   程序   Laravel

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!