[英]Laravel: Add a custom query before login / Auth
我是新來的,剛開始使用 Laravel,
我想在用戶單擊“登錄”按鈕之前添加一個新查詢。
例如:在用戶輸入他的用戶名和密碼並點擊登錄按鈕后,
如果用戶名存在於不同的表中,我想先進行查詢。
if (exists) {
// do laravel default auth.
} else {
// add the username in the table
// do laravel default auth.
}
希望有人可以幫助我,。
謝謝
如果是這種情況,那么您必須自定義laravel 提供的默認登錄方法。 看下面的代碼
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
class LoginController extends Controller
{
/**
* Handle an authentication attempt.
*
* @param \Illuminate\Http\Request $request
*
* @return Response
*/
public function login(Request $request)
{
$credentials = $request->only('username', 'password');
$username = Othertable::where('username', $request->username)->get();
if($username->count() > 0 ) {
if (Auth::attempt($credentials)) {
// Authentication passed...
return redirect()->intended('dashboard');
}
} else {
//add the username in the table
//do laravel default auth.
}
}
}
在此處閱讀文檔身份驗證
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.