簡體   English   中英

如何使用管理員保護設置管理員會話與我們在用戶中使用的相同

[英]How can I setting admin session using admin guards the same as we use in user

我有學生表,我需要他們訪問管理員發送的表格並應用它們,我試圖使用數據透視表訪問,但似乎我需要有不同的表來訪問從管理員到學生的表格,然后檢索他們回來(由管理員),但它告訴我

“方法Illuminate \\ Auth \\ SessionGuard :: admin不存在”

我嘗試設置多個身份驗證並為admin設置防護,但似乎需要一個會話,以便我可以使用auth()->admin()->nameauth()->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 \\資源\\意見\\繼承\\ admin.blade.php)”

我通過在刀片中編寫簡單代碼來解決問題我檢查是否是客人然后如果不是我繼續'

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM