问题
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.
回答1:
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.
回答2:
If you're using Laravel when you run into this error, just run:
composer require guzzlehttp/guzzle
And try again.
回答3:
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
回答4:
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
回答5:
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
回答6:
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.
回答7:
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.
回答8:
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.
回答9:
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.
来源:https://stackoverflow.com/questions/31227080/laravel-class-guzzlehttp-client-not-found