Laravel 8 多個身份驗證 guard

2021-07-26 09:52 更新

如果您的應(yīng)用程序可能使用完全不同的 Eloquent 模型、不同類型的用戶進行身份驗證,則可能需要為應(yīng)用程序中的每種用戶設(shè)置 guard。 這使您可以保護特定 guard 的請求。 例如,設(shè)置以下 guard config/auth.php 配置文件:

'api' => [
    'driver' => 'passport',
    'provider' => 'users',
],

'api-customers' => [
    'driver' => 'passport',
    'provider' => 'customers',
], 

以下路由將使用 customers 用戶提供者的 api-customers guard 來驗證傳入的請求:

Route::get('/customer', function () {
    //
})->middleware('auth:api-customers'); 

技巧:有關(guān)在 Passport 上使用多個用戶提供者的更多信息,請查閱密碼授予文檔.


以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號