2013-09-22 65 views
0

我試圖對我的表單進行後端驗證,但它不起作用。它總是表明驗證失敗,即使我提交了值。Laravel驗證不起作用,總是失敗

代碼

$validation = Validator::make(Input::all(), array(
    array('email' => 'required'), 
    array('password' => 'required') 
)); 

if ($validation->fails()) { // This is always failing 
    echo '<pre>'; 
    print_r(Input::all()); 
    die(); 
} 

die('everything is OK!'); 

輸出

Array 
(
    [_token] => ZnzZ2aDoTABIZZkvwxZoa7IjHkvK25ndibis5AbA 
    [email] => somedata 
    [password] => somemoredata 
) 

正如你可以看到它失敗甚至壽它清楚地從值設置Input:all()顯示。

+0

提取錯誤,看看它爲什麼失敗? – itachi

回答

4

變化:

$validation = Validator::make(Input::all(), array(
    array('email' => 'required'), 
    array('password' => 'required') 
)); 

$validation = Validator::make(Input::all(), array(
    'email' => 'required|email', // Note that I added in valid email rule here also 
    'password' => 'required' 
)); 
+1

這裏不應該有任何區別。 – itachi

+0

@itachi它做到了。 – sed

+1

這裏的工作不是「email」標誌,而是修復** double array **錯誤......查看我的答案。 – grena

6

試試這個:

$validation = Validator::make(Input::all(), array(
    'email' => 'required', 
    'password' => 'required' 
)); 

不是雙陣列像你一樣:

$validation = Validator::make(Input::all(), array(
    array('email' => 'required'), // Is shouldn't be an array here. 
    array('password' => 'required') 
)); 
+0

^^你有brotha。 – wesside