我有一个学生表,我需要他们访问管理员发送的表单并应用它们,正在尝试使用数据透视表进行访问,但似乎我需要使用不同的表来访问从管理员到学生的表单然后通过管理员撤退它们,但这告诉我
“方法Illuminate \ Auth \ SessionGuard :: admin不存在”
我尝试设置多个身份验证并为管理员设置了保护措施,但似乎需要进行会话,这样我才能像使用auth()->admin()->name
一样使用auth()->user()->name
,如果有的话,我现在感到非常沮丧设置这两个会话(用户和管理员)的任何可能性,请问如何完成,谢谢。
下面是我的守卫
<?php
return [
/*
|--------------------------------------------------------------------------
| Authentication Defaults
|--------------------------------------------------------------------------
|
| This option controls the default authentication "guard" and password
| reset options for your application. You may change these defaults
| as required, but they're a perfect start for most applications.
|
*/
'defaults' => [
'guard' => 'web',
'passwords' => 'users',
],
// 'admins' => [
// 'driver' => 'eloquent',
// 'model' => App\Admin::class,
// ],
// 'defaults' => [
// 'driver' => 'session',
// 'provider' => 'admins',
// ],
/*
|--------------------------------------------------------------------------
| Authentication Guards
|--------------------------------------------------------------------------
|
| Next, you may define every authentication guard for your application.
| Of course, a great default configuration has been defined for you
| here which uses session storage and the Eloquent user provider.
|
| All authentication drivers have a user provider. This defines how the
| users are actually retrieved out of your database or other storage
| mechanisms used by this application to persist your user's data.
|
| Supported: "session", "token"
|
*/
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'users',
],
'api' => [
'driver' => 'token',
'provider' => 'users',
'hash' => false,
],
'admin' => [
'driver' => 'session',
'provider' => 'admins',
],
'admin-api' => [
'driver' => 'token',
'provider' => 'admins',
],
],
/*
|--------------------------------------------------------------------------
| User Providers
|--------------------------------------------------------------------------
|
| All authentication drivers have a user provider. This defines how the
| users are actually retrieved out of your database or other storage
| mechanisms used by this application to persist your user's data.
|
| If you have multiple user tables or models you may configure multiple
| sources which represent each model / table. These sources may then
| be assigned to any extra authentication guards you have defined.
|
| Supported: "database", "eloquent"
|
*/
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => App\User::class,
],
'admins' => [
'driver' => 'eloquent',
'model' => App\Admin::class,
],
// 'users' => [
// 'driver' => 'database',
// 'table' => 'users',
// ],
],
/*
|--------------------------------------------------------------------------
| Resetting Passwords
|--------------------------------------------------------------------------
|
| You may specify multiple password reset configurations if you have more
| than one user table or model in the application and you want to have
| separate password reset settings based on the specific user types.
|
| The expire time is the number of minutes that the reset token should be
| considered valid. This security feature keeps tokens short-lived so
| they have less time to be guessed. You may change this as needed.
|
*/
'passwords' => [
'users' => [
'provider' => 'users',
'table' => 'password_resets',
'expire' => 60,
],
'admins' => [
'provider' => 'admins',
'table' => 'password_resets',
'expire' => 60,
],
],
];
我希望以管理员身份登录,并使用与用户模型中相同的登录方式 但是我遇到了这个错误
“ ErrorException(E_ERROR)方法照亮\ Auth \ SessionGuard :: admin 不存在。 (视图: C:\ xampp \ htdocs \ ftss \ resources \ views \ inherit \ admin.blade.php)(查看: C:\ xampp \ htdocs \ ftss \ resources \ views \ inherit \ admin.blade.php)“
答案 0 :(得分:0)
我通过在刀片中编写简单的代码解决了这个问题 我检查是否有客人,否则我继续 '
@guest
@else
{{auth()->user()->name}}
@endguest
'