代码之家  ›  专栏  ›  技术社区  ›  eComEvo

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

  •  0
  • eComEvo  · 技术社区  · 12 年前

    我正在尝试验证此输入:

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

    根据我的Schedule类中的这些规则:

    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/vvendor/laravel/framework/src/Iuminate/Validation/Validator.php”中得到一个数组到字符串的转换错误:

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

    为什么会发生这种情况?

    1 回复  |  直到 12 年前
        1
  •  1
  •   eComEvo    10 年前

    刚刚发现我有雅顿的 $forceEntityHydrationFromInput = true 我的输入不能直接从 Input 由于它是作为一个部分引用值数组提交的,因此出于验证目的。

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

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