2017-09-03 28 views
0

我已經試圖按照documentation,但我沒有成功。 我需要一個條件添加到原來的登錄系統在laravel中如何個性化登錄

我已經試過如下:

namespace App\Http\Controllers\Auth; 

use App\Http\Controllers\Controller; 
use Illuminate\Foundation\Auth\AuthenticatesUsers; 
use Illuminate\Support\Facades\Auth; 

class LoginController extends Controller 
{ 

    use AuthenticatesUsers; 

    protected $redirectTo = '/'; 

    public function authenticate() 
    { 
     if (Auth::attempt(['email' => $email, 'password' => $password, 'type' => 'cliente'])) { 

      dd('autenticate'); 

     } 
    } 

} 

我的路線

Route::post('/login', 'Auth\[email protected]'); 

的埃羅:

ErrorException: Undefined variable: email in /var/www... 

不任何人都知道我可以做到這一點?

----------- -----------決議:

我不知道這是否是最安全的方式,但它的工作是這樣的:

public function authenticate(Request $request) 
{ 

    $this->validateLogin($request); 

    $input=$request->all(); 
    $password=$input['password']; 
    $email=$input['email']; 

    if (Auth::attempt(['email' => $email, 'password' => $password, 'type'=>'cliente'])) { 

     return redirect()->intended('/'); 
    } 

    $this->incrementLoginAttempts($request); 

    return $this->sendFailedLoginResponse($request); 
} 

我的路線:

Route::post('/login', 'Auth\[email protected]'); 
+0

向我們展示'login'函數。 – Wreigh

+0

@Wreigh我操縱的控制器LoginController中不存在函數login;此功能位於供應商文件夾 –

+0

內的AuthenticatesUsers類別內,錯誤或問題是什麼?什麼不工作? – Wreigh

回答

0

您可以更改憑據。你不需要單獨的authenticate方法。在LoginController覆蓋這個函數是在特質:

namespace App\Http\Controllers\Auth; 

use App\Http\Controllers\Controller; 
use Illuminate\Foundation\Auth\AuthenticatesUsers; 
use Illuminate\Support\Facades\Auth; 
use Illuminate\Http\Request; //*****add this 

class LoginController extends Controller { 

    use AuthenticatesUsers; 

    protected $redirectTo = '/'; 

    ** 
    * Get the needed authorization credentials from the request. 
    * 
    * @param \Illuminate\Http\Request $request 
    * @return array 
    */ 
    protected function credentials(Request $request){ 
     return array_merge($request->only($this->username(), 'password'), ['type' => 'cliente']); 
    } 
} 

希望這是有幫助的。