首页 > 解决方案 > 如何使用与我们在用户中使用的相同的管理员防护设置管理员会话

问题描述

我有学生表,我需要他们访问管理员发送的表格并应用它们,我正在尝试使用数据透视表进行访问,但似乎我需要有不同的表格来访问从管理员到学生的表格,然后检索它们返回(由管理员),但它告诉我

“方法 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)"

标签: phplaravel

解决方案


我通过在刀片中编写简单的代码解决了这个问题我检查是否是客人然后如果不是我继续'

@guest
@else
{{auth()->user()->name}}
@endguest

'


推荐阅读