So i put this code on the method register() inside the AppServiceProvider:
public function register()
{
$this->app->singleton(GuzzleHttp\Client::class, function($app) {
return new Client([
'base_uri' => env('API_BASE_URI'),
'headers' => ['X-API-Key' => env('API_KEY')],
'curl' => [
CURLOPT_SSL_VERIFYPEER => false
]
]);
});
}
but when i do a new instance it simply doesn't work, i know that it doesn't work because on my controller i did:
$client = new GuzzleHttp\Client();
dd($client);
and the debugger page doesnt show the X-API-Key on the headers key that i put on the singleton closure, so, what am i doing wrong?
This is what it shows:
"headers" => array:1 [▼
"User-Agent" => "GuzzleHttp/6.5.3 curl/7.68.0 PHP/7.4.3"
]
This is what should show:
"headers" => array:1 [▼
"User-Agent" => "GuzzleHttp/6.5.3 curl/7.68.0 PHP/7.4.3"
"X-API-Key" => "My API Key Here"
]