Laravel Validator fails due to array to string con

2019-03-04 13:48发布

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                                 
];

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'                                                                            
];

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;
}

Why would this be happening?

1条回答
何必那么认真
2楼-- · 2019-03-04 14:43

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.

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.

查看更多
登录 后发表回答