[英]How to call method from AdminAuthServiceProvider in a laravel controller?
在AuthServiceProvider中,我在啟動功能中有以下行。
Auth::provider('customer', function($app, array $config){
return new CustomerAuthServiceProvider();
});
我需要在控制器中調用CustomerAuthServiceProvider中的方法。 我可以做嗎 ?
在config/App.php
的提供者列表中注冊您的CustomerAuthServiceProvider
; 然后使用其別名use CustomerAuth
(您可以使用任何別名)在控制器頂部的Controller中調用它。 https://laravel.com/docs/5.8/providers
可通過Illuminate\\Auth\\AuthManager
Illuminate\\Auth\\CreatesUserProviders
特性訪問createUserProvider
方法
您可以通過Illuminate\\Support\\Facades\\Auth
Facade獲取AuthManager
類的實例。
use Illuminate\Support\Facades\Auth;
//...
class WhatController extends Controller {
public function index()
{
$provider = Auth::createUserProvider('customer');
}
}
請注意, customer
輸入必須包含在config/auth.php
中的providers
數組中
providers' => [
//...
customer' => [
'driver' => 'eloquent',
'model' => App\WhatCustomer::class,
]
]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.