php - 如何使用与我们在用户中使用的相同的管理员防护设置管理员会话
问题描述
我有学生表,我需要他们访问管理员发送的表格并应用它们,我正在尝试使用数据透视表进行访问,但似乎我需要有不同的表格来访问从管理员到学生的表格,然后检索它们返回(由管理员),但它告诉我
“方法 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)"
解决方案
我通过在刀片中编写简单的代码解决了这个问题我检查是否是客人然后如果不是我继续'
@guest
@else
{{auth()->user()->name}}
@endguest
'
推荐阅读
- r - R - 过滤数据框以仅包含列数符合条件的行
- react-native - 如何将标题传递到抽屉导航器(React Navigation V5)
- php - PHP socket_write 失败仅在下次调用时返回错误
- python - PyCharm - 将 Sources Root 添加到 GitHub
- c++11 - 悬停在 QLabel 上后如何可视化 QPushButton
- c++ - 工会成员的偏移量总是为零吗?
- reactjs - 当这些元素位于具有更高 z-index 的 div 下时,如何使用 testing-library 的 findByText() 查找元素?
- html - 如何定位其他所有图形标签?
- python - 我无法为代码创建最后 3 条规则
- typescript - 为什么 Typescript 不能在赋值中使用泛型的 keyof 类型并将其泛化为字符串?