laravel 內置auth()登錄


auth()命令

auth()->attempt()        登錄驗證

auth()->check        判斷是否登錄,有沒有session緩存

auth()->loginout()        清除緩存   退出登錄時使用

auth()->user()        獲取當前認證用戶

配置

app/config/auth.php

'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => \App\Models\Login::class, //這是你要驗證的登錄表對應的模型層
],
],

模型層中

use Illuminate\Foundation\Auth\User as Auth;

class Login extends Auth //這里Auth是上面修改的
{
//黑名單
protected $guarded= [];
//綁定表
protected $table='login'; //如果不寫模型名Login,表對應Logins,看自己對應好沒,沒對應好就指定表
}

控制器中

public function index(){
if (auth()->check()){
return redirect(route('admin.index')); //這里就進行auth驗證了,成功就跳轉到首頁
}
return view('admin.login.login'); //失敗還是在登錄頁面
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM