【发布时间】:2019-06-04 02:38:21
【问题描述】:
我有学生表,我需要他们访问管理员发送的表单并应用它们,我正在尝试使用数据透视表进行访问,但似乎我需要不同的表来访问从管理员到学生的表单然后将它们取回(由管理员),但它告诉我
“方法 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) 方法 Illuminate\Auth\SessionGuard::admin 不存在。 (看法: C:\xampp\htdocs\ftss\resources\views\inherit\admin.blade.php)(查看: C:\xampp\htdocs\ftss\resources\views\inherit\admin.blade.php)"
【问题讨论】:
-
你有管理员模型吗?
-
@Makaveli 而不是检查管理员为什么不检查用户是否登录?
-
并根据用户角色管理条件。
-
@Makaveli 澄清一件事......每个学生都有自己的登录名吗?
-
我解决了.. 问题出在控制器中,我必须使用一些中间件