问题描述
我正在研究Laravel Lumen项目。我不是在尝试从AuthServiceProvider类内的请求中检索标头值,如下所示。
class AuthServiceProvider extends ServiceProvider
{
/**
* Register any application services.
*
* @return void
*/
public function register()
{
//
}
/**
* Boot the authentication services for the application.
*
* @return void
*/
public function boot()
{
// Here you may define how you wish users to be authenticated for your Lumen
// application. The callback which receives the incoming request instance
// should return either a User instance or null. You're free to obtain
// the User instance via an API token or any other method necessary.
$this->app['auth']->viaRequest('api',function ($request) {
if ($request->input('api_token')) {
return User::where('api_token',$request->input('api_token'))->first();
}
});
$request = $this->app->request;
dd($request->header("api-key"));
}
}
但是它不起作用。它总是返回null。我也尝试了以下方法。
request()->header('api-key');
那也不起作用。但是我可以在中间件或控制器中检索值。它只是在服务提供商类内部不起作用。我该如何解决?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)