urakozz / laravel-guzzle by urakozz
forked from thbourlove/laravel-guzzle

Guzzle 5/6 Service Provider for Laravel
723,206
63
6
Package Data
Maintainer Username: urakozz
Maintainer Contact: thbourlove@gmail.com (Hongbo Tang)
Package Create Date: 2015-04-16
Package Last Update: 2024-03-04
Home Page:
Language: PHP
License: MIT
Last Refreshed: 2024-04-26 03:01:53
Package Statistics
Total Downloads: 723,206
Monthly Downloads: 14,591
Daily Downloads: 562
Total Stars: 63
Total Watchers: 6
Total Forks: 12
Total Open Issues: 0

Laravel - Guzzle 6 (or 5) Service Provider

Downloads Packagist Version

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="