2015-04-24 97 views
2

我得到錯誤'沒有查詢結果的模型[應用程序用戶]',當我試圖找到一個用戶與此查詢。Laravel - 無查詢結果模型

 if(User::where('email', '=', Request::only('email'))->firstOrFail()){ 
     $validator->errors()->add(...); 
    } 

回答

2

Request::only()實際上會返回一個數組。在你的情況:['email' => 'the-value-of-email']。做這一點:

User::where(Request::only('email'))->firstOrFail() 

或者只是使用Request::input()僅檢索值:

User::where('email', '=', Request::input('email'))->firstOrFail()