kozz / laravel-guzzle-provider
Guzzle 5/6 Service Provider for Laravel
7.3.0
2024-03-04 12:30 UTC
Requires
- php: ^7.2|^8.0
- guzzlehttp/guzzle: ^7.0
- illuminate/support: ^5.0 | ^6.0| ^7.0 | ^8.0 | ^9.0|^10.0|^11.0
Requires (Dev)
- phpunit/phpunit: ~4.0|^9.5.10|^10.5
README
laravel guzzle service provider
Install With Composer:
Guzzle ~5.0
composer require kozz/laravel-guzzle-provider ~5.0
Or manualy in composer.json:
"require": { "kozz/laravel-guzzle-provider": "~5.0" }
Guzzle ~6.0
composer require kozz/laravel-guzzle-provider ~6.0
Or manualy in composer.json:
"require": { "kozz/laravel-guzzle-provider": "~6.0" }
Setup
Laravel >=5.5
This package supports auto discovery, so no configuration is required.
Laravel <5.5
Register Service Provider
/configs/app.php
... 'providers' => [ /* * Laravel Framework Service Providers... */ ... /* * Application Service Providers... */ ... 'Kozz\Laravel\Providers\Guzzle' ],
Enable Facade
/configs/app.php
... 'aliases' => [ ... 'Guzzle' => 'Kozz\Laravel\Facades\Guzzle' ],
Usage
Send request
$response = \Guzzle::get('https://google.com');
Get instance
$client = app()->offsetGet('guzzle'); $client = \Illuminate\Container\Container::getInstance()->offsetGet('guzzle'); $client = \Kozz\Laravel\Facades\Guzzle::getFacadeRoot(); $client = \Guzzle::getFacadeRoot();
POST
$response = Guzzle::post( 'https://httpbin.org/post', [ 'form_params' => [ 'id' => 222 ] ] );
Basic auth
$response = Guzzle::post( 'https://httpbin.org/post', [ 'auth' => [ 'theUsername', 'thePassword'], ] );
generates:
+"Authorization": "Basic dGhlVXNlcm5hbWU6dGhlUGFzc3dvcmQ="