[英]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.