0

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?

eComEvo
  • 11,669
  • 26
  • 89
  • 145

1 Answers1

1

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.

eComEvo
  • 11,669
  • 26
  • 89
  • 145
  • @grald it's set in the attributes of your model. If you didn't set it in the first place, this likely isn't your problem. – eComEvo Dec 17 '15 at 01:01
  • i don't know it yet because i never set actually i am using L5.1 – Grald Dec 17 '15 at 01:25