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'); //失敗還是在登錄頁面
}