2014-09-05 56 views
0

我試圖驗證此輸入:Laravel驗證失敗,因爲數組字符串轉換

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

根據這些規則在我的日程表類中發現:當我這樣做

public static $rules = [                       
    'template_id'   => 'required|integer|exists:templates,id',           
    'schedulable_id'  => 'required|integer',                 
    'schedulable_type'  => 'required|in:Item,Order', 
    'order_by'    => 'integer'                    
]; 

$validator = Validator::make($values, Schedule::$rules); 

if ($validator->fails()) { 
    $errors[$i] = $validator->messages(); 

    continue; 
} 
我總是在905行獲取數組在「/laravel/vendor/laravel/framework/src/Illuminate/Validation/Validator.php」字符串轉換錯誤

爲什麼會發生這種情況?

回答

1

剛剛發現我有Ardent的$forceEntityHydrationFromInput = true,並且我的輸入無法從Input直接拉出來用於驗證,因爲它是作爲部分參考值數組提交的。

要解決此問題,請更改爲$forceEntityHydrationFromInput = false並使用標準輸入驗證程序,而不是依靠Ardent的魔法。

有時候聰明的軟件包太聰明瞭。

+0

我不明白你是怎麼解決這個錯誤的? – Grald 2015-12-16 12:50:50

+0

@Grald剛剛更新了答案,以澄清。 – eComEvo 2015-12-16 19:30:01

+0

在哪裏可以找到? – Grald 2015-12-16 21:55:55

相關問題