I am working on a Laravel Lumen project. I am not trying to retrieve the header values from the request inside the AuthServiceProvider class as follow.
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"));
}
}
But it is not working. It is always returning null. I tried the following too.
request()->header('api-key');
That is not working either. But I can retrieve the values inside the middlewares or controllers. It is just not working inside the service provider class. How can I fix it?