我有数据库表名admins,并且我想为这些表格创建登录会话,我尝试使用中间件会话防护来创建登录功能,但是在下面收到通知错误:
方法Illuminate \ Auth \ SessionGuard :: admin不存在。 (查看:C:\ xampp \ htdocs \ weddinc \ weddinc7 \ weddinc \ resources \ views \ layouts \ admin_layout.blade.php)
有人可以帮助我解决此问题吗? 注意:我使用的是Laravel 6.2 Framework PHP
这是我的控制人:
...
public function login(Request $request)
{
if (Auth::guard('owner')->attempt(['email' => $request->email, 'password' => $request->password ])) {
return redirect()->intended(route('index.owner'));
}
return back()->withInput($request->only('email', 'remember'));
}
...
}
这是我的视图:
...
<div class="d-sm-none d-lg-inline-block">{{ auth()->admin()->name }}</div></a>
...
这是我的Guard配置/身份验证:
<?php
return [
'defaults' => [
'guard' => 'web',
'passwords' => 'users',
],
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'users',
],
'api' => [
'driver' => 'passport',
'provider' => 'users',
'hash' => false,
],
'owner' => [
'driver' => 'session',
'provider' => 'owners',
],
'admin' => [
'driver' => 'session',
'provider' => 'admins',
],
],
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => App\User::class,
],
'owners' => [
'driver' => 'eloquent',
'model' => App\Owner::class,
],
'admins' => [
'driver' => 'eloquent',
'model' => App\Admin::class,
],
],
'passwords' => [
...
'admins' => [
'provider' => 'admins',
'table' => 'password_reset',
'expire' => 60,
],
],
];
有人可以帮助我吗?谢谢
答案 0 :(得分:0)
尝试在视图中像这样访问
<div class="d-sm-none d-lg-inline-block">{{ \Auth::guard('admin')->user()->name }}</div></a>
答案 1 :(得分:0)
您需要使用用户而不是用户,用户已获得Auth身份验证,并将获得当前登录的用户ID。
$id = \Auth::user()->id;
或者您想吸引用户
$user = \Auth::user();