I always create my own HttpClient which extends \Illuminate\Support\Facades\Http and I set everything in my class that I need.
Http Client with Default Settings
Hey Guys,
Hoping you can help me. I am using the HTTP Client in L8, but I was wondering if there was a way I could set it so whenever I call the facade, there was always some default stuff passed with it I figured using a service provider might be the way to do it, but I get an error with some tests that the method fake() does not exist, so I guess, its returning an instance of pending request, rather than the factory, but I am not sure how to combat that when I take this approach, I tried to tap the factory, but this returns without the options.
public function register() {
$this->app
->bind(
Factory::class,
static fn ($app) => (new Factory)->withOptions(['proxy' => 'x.x.x.x']),
);
}
If anyone has some thoughts on how this might be achieved, I would be most greatful.
Ta, Andrew
@xoctopus Taylor Otwell suggested a great way of doing this with Macros in a PR that was recently submitted: https://github.com/laravel/framework/pull/40332
Please or to participate in this conversation.