InvalidSyntax
InvalidSyntax

Reputation: 9495

Laravel: Class 'GuzzleHttp\Client' not found

I am trying to use Mandrill to send emails via my Laravel framework, however I am receiving the following error:

FatalErrorException in MandrillTransport.php line 114: Class 'GuzzleHttp\Client' not found

I have installed Guzzle using the following command in Terminal:

"guzzlehttp/guzzle": "~4.0"

According to Laravel's documentation I need to add "guzzlehttp/guzzle": "~4.0" to my composer.json file, but I'm not sure if where I have placed it is correct as I still see the error.

{
    "name": "laravel/laravel",
    "description": "The Laravel Framework.",
    "keywords": ["framework", "laravel"],
    "license": "MIT",
    "type": "project",
    "require": {
        "laravel/framework": "5.0.*",
        "illuminate/html": "^5.0",
        "guzzlehttp/guzzle": "~4.0"
    },
    "require-dev": {
        "phpunit/phpunit": "~4.0",
        "phpspec/phpspec": "~2.1"
    },
    "autoload": {
        "classmap": [
            "database"
        ],
        "psr-4": {
            "App\\": "app/"
        }
    },
    "autoload-dev": {
        "classmap": [
            "tests/TestCase.php"
        ]
    },
    "scripts": {
        "post-install-cmd": [
            "php artisan clear-compiled",
            "php artisan optimize"
        ],
        "post-update-cmd": [
            "php artisan clear-compiled",
            "php artisan optimize"
        ],
        "post-create-project-cmd": [
            "php -r \"copy('.env.example', '.env');\"",
            "php artisan key:generate"
        ]
    },
    "config": {
        "preferred-install": "dist"
    }
}

Here is the list of packages my application has, notice that guzzle has a different version: 4.2.3 which i've also tried updating to but still get the same error. list of packages installed

Upvotes: 39

Views: 114684

Answers (11)

Kiefer
Kiefer

Reputation: 13

I had the exact same issue. I resolved it by adding

require 'vendor/autoload.php'

to the top of the file.

My autoload.php includes theses lines from Guzzle

'GuzzleHttp\\Psr7\\' => array($vendorDir . '/guzlehttp/psr7/src'),

'GuzzleHttp\\Promise\\' => array($vendorDir . '/guzzlehttp/promises/src'),

'GuzzleHttp\\' => array($vendorDir . '/guzzlehttp/guzzle/src'),

"Autoload is a method to load and use classes. Using Autoload, we can load and call classes everywhere instead of including classes at the beginning of each PHP file. Therefore, we don’t need to load all classes in the library for all PHP files." quoted from - https://metabox.io/composer-and-autoload-in-php/

Upvotes: 1

Joshua Johns
Joshua Johns

Reputation: 373

Try updating your composer to latest version might end sorting your problem. This worked out for me. Ubuntu/Linux users use this tutorial in Digital ocean

Upvotes: 0

shampoo
shampoo

Reputation: 1281

Open up your terminal at the root of your project and enter

composer require guzzlehttp/guzzle

It worked for the mailgun API. For some reason, the suggested method at the laravel's mail doc. You may install this package to your project by adding the following line to your composer.json file

"guzzlehttp/guzzle": "~5.3|~6.0"

doesn't make the composer download the Guzzle source codes. By the way, I didn't find out what | means in determining the version. This command just downloads the PSR code.

In this moment, the solution may work. However, be aware of compatibility issues. Because the command would install the latest stable version, not the suitable one.

Upvotes: 39

Muhammad Sulman
Muhammad Sulman

Reputation: 1681

simple in my case add "guzzlehttp/guzzle": "^6.3" in composer.json require object as mentioned below

"require": {
        "php": ">=7.0.0",
        "ext-gd": "*",
        "barryvdh/laravel-cors": "^0.11.2",
        "barryvdh/laravel-dompdf": "^0.8.1",
        "dingo/api": "2.0.0-alpha1",
        "doctrine/dbal": "^2.6",
        "fideloper/proxy": "~3.3",
        "guzzlehttp/guzzle": "^6.3",
        "intervention/image": "^2.4",
        "laravel/framework": "5.5.*",
        "laravel/tinker": "~1.0",
        "league/flysystem-aws-s3-v3": "~1.0",
        "predis/predis": "^1.1",
        "tymon/jwt-auth": "dev-develop"
    }, 

than run composer update in project root using terminal than its working fine.

Upvotes: 1

Grant
Grant

Reputation: 6309

If you're using Laravel when you run into this error, just run:

composer require guzzlehttp/guzzle

And try again.

Upvotes: 15

Goktug Gumus
Goktug Gumus

Reputation: 129

You can solve this problem to add "mews/captcha": "1.0.1" and "guzzlehttp/guzzle": "~4.0" to your composer.json file. And then you need run composer update command on your terminal.

I have tried on Laravel 4. It works for me.

Upvotes: 0

Larzack
Larzack

Reputation: 21

I had the same issue. I used an old version in order to work. It's not working anymore since version 4. It works on version 3.8.1

So you can add "guzzlehttp/guzzle": "~3" to works

Upvotes: 2

boateng
boateng

Reputation: 898

I got this error when I tried running my code outside of the Laravel framework while testing in a stand alone file. It worked for me when I moved it inside a controller.

Upvotes: 0

Gokigooooks
Gokigooooks

Reputation: 794

I am oblivious to why this worked for me, I saw this in a forum somewhere

I just added this captcha generator to the composer.json file

"mews/captcha": "~2.0.",

added it to all the require package

"require": {
    "php": ">=5.5.9",
    "laravel/framework": "5.1.*",
    "laravelcollective/html": "5.1.*",
    "laracasts/flash": "~1.3",
     "mews/captcha": "~2.0.",
    "guzzlehttp/guzzle": "~4.0"
    },

If someone knows why this worked it would really scratch the itch in my brain.

Upvotes: 0

Ju Chépa
Ju Chépa

Reputation: 67

Did you try :

artisan clear-compiled 

or if artisan is not available try to remove compiled.php if exist (in vendor directory) and launch composer dumpautoload

Upvotes: 2

Paul
Paul

Reputation: 141819

After updating your composer.json file you need to run the update command to resolve and install your dependencies:

composer update

or, if composer isn't in your path:

php composer.phar update

Upvotes: 7

Related Questions