2017-07-18 198 views
0

這是我的LoginController,我想顯示自定義登錄錯誤消息「Invaild password」。我該怎麼辦?請善意幫助我!提前致謝。登錄錯誤消息Laravel

* -

> <?php namespace App\Http\Controllers\Auth; use 
    > App\Http\Controllers\Controller; use 
    > Illuminate\Foundation\Auth\AuthenticatesUsers; use 
    > Illuminate\Http\Request; class LoginController extends Controller { 
    >  use AuthenticatesUsers; 
    >  /** 
    >  * Where to redirect users after login. 
    >  * 
    >  * @var string 
    >  */ 
    >  protected $redirectTo = '/Dashboards'; 
    >  /** 
    >  * Create a new controller instance. 
    >  * 
    >  * @return void 
    >  */ 
    >  public function __construct() 
    >  { 
    >   $this->middleware('guest', ['except' => 'logout']); 
    >  } 
    >  public function username() 
    >  { 
    >   return 'username'; 
    >  } 
    >  /** 
    >  * Log the user out of the application. 
    >  * 
    >  * @param \Illuminate\Http\Request $request 
    >  * @return \Illuminate\Http\Response 
    >  */ 
    >  public function logout(Request $request) 
    >  { 
    >   $this->guard()->logout(); 
    >   $request->session()->flush(); 
    >   $request->session()->regenerate(); 
    >   return redirect('/login'); 
    >  } } 
*** 

回答

0

改變這一行src/resources/lang/en/auth.php

'failed' => 'These credentials do not match our records.', 

如果您沒有在您的網頁語言翻譯文件,你會得到默認的英語翻譯。

你需要在你的那種。我已經做到了這一點vendor/laravel/framework/src/Illuminuate/Auth/AuthenticatesUser.php

/** 
    * Get the failed login message. 
    * 
    * @return string 
    */ 
    protected function getFailedLoginMessage() 
    { 
     return Lang::has('auth.failed') 
       ? Lang::get('auth.failed') 
       : 'These credentials do not match our records.'; 
    } 
+0

感謝好友超越此功能。但它不工作:( – blackWaterLiLi

+0

消息是英語嗎? –

+0

是的我想顯示我的錯誤消息,如「無效的用戶名和密碼,請再試一次! – blackWaterLiLi