Laravel: Class 'GuzzleHttp\Client' not found - php

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.

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.

If you're using Laravel when you run into this error, just run:
composer require guzzlehttp/guzzle
And try again.

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

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

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

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.

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.

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.

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.

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

Related

How to make laravel a composer dependency for my project

My project is a Laravel implementation. I have created a composer.json file as follows:
{
"name": "company/project",
"description": "My cool project.",
"type": "project",
"license": "proprietary",
"require": {
"laravel/laravel": "8.*"
}
}
I can put this file in its own directory and run composer install. This installs version 8 of laravel/laravel and all dependencies in the vendor/ directory. But this is not a valid Laravel installation. If I then move the contents of vendor/laravel/laravel up into the main directory, copy .env.example to .env and run composer -o dump-autoload, then I have a directory structure that looks (as far as I can tell), just like a standard Laravel installation.
However, when I try to access the site from by browser, I get a 500 Server Error, with no apparent entries in the Apache or Laravel logs.
I know this is not an Apache configuration error because I can create exactly the same site using the command composer create-project laravel/laravel:8.* {directory}, and I get a function basic Laravel site.
My ultimate goal is to use composer to install my project AND Laravel, with all of it's dependencies, and get a functioning site. I am particularly interested in being able to lock all of the dependencies (including the specific version of laravel/laravel) via the composer.lock file, which will then be included with the version-controlled source of my project.
You may ask why I don't just use the recommended command to create a clean Laravel installation and just version-control the resultant composer.lock file. The reason is: That file does not contain the specific version of laravel/laravel. So when I then user the composer.json/lock files in a clean directory, the core laravel/larvel files are missing.
Any pointers as to what I am doing wrong? Or is there a simpler way to achieve my goal?
Your composer.json only requires "laravel/laravel": "8.*", but Laravel needs a lot more to function properly. When I do a composer create-project laravel/laravel it generates a composer.json with the following:
{
"name": "laravel/laravel",
"type": "project",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"require": {
"php": "^7.3|^8.0",
"fruitcake/laravel-cors": "^2.0",
"guzzlehttp/guzzle": "^7.0.1",
"laravel/framework": "^8.54",
"laravel/sanctum": "^2.11",
"laravel/tinker": "^2.5"
},
"require-dev": {
"facade/ignition": "^2.5",
"fakerphp/faker": "^1.9.1",
"laravel/sail": "^1.0.1",
"mockery/mockery": "^1.4.2",
"nunomaduro/collision": "^5.0",
"phpunit/phpunit": "^9.3.3"
},
"autoload": {
"psr-4": {
"App\\": "app/",
"Database\\Factories\\": "database/factories/",
"Database\\Seeders\\": "database/seeders/"
}
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/"
}
},
"scripts": {
"post-autoload-dump": [
"Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
"#php artisan package:discover --ansi"
],
"post-update-cmd": [
"#php artisan vendor:publish --tag=laravel-assets --ansi"
],
"post-root-package-install": [
"#php -r \"file_exists('.env') || copy('.env.example', '.env');\""
],
"post-create-project-cmd": [
"#php artisan key:generate --ansi"
]
},
"extra": {
"laravel": {
"dont-discover": []
}
},
"config": {
"optimize-autoloader": true,
"preferred-install": "dist",
"sort-packages": true
},
"minimum-stability": "dev",
"prefer-stable": true
}
Now this does a lot more than just requiring a vendor-folder, these contain the namespace-declarations, scripts, and the requirements for a few more things.
And also note that this requires laravel/framework instead of laravel/laravel.
All in all I suggest using the full list from here and keep stripping until it breaks if you want to.
And on the subject of version pinning, you could either put the composer.lock-file in your VCS and only run composer install (that does not update if there is lock-file).
You could also remove the ^ from all the versions that you don't want to update, that way you can restrict a version with some room for updates if you want. 8.0.1 would keep at 8.0.1, but you could allow patches by specifying 8.0.* as a version-requirement.
In the end, I gave up trying to make this work. Instead, I now follow these steps to install a new site:
composer create-project --no-install --no-scripts laravel/laravel:{version} {SITE}
cd {SITE}
svn export --force {repo}/composer.json .
svn export --force {repo}/composer.lock .
composer install
svn co {repo} .
svn -R revert .
This allows me to create a site with the specific version of Laravel that I need.

After update to Laravel 7 php artisan not working

after upgrading Laravel according to the docs to v7 I ran composer update. Then I'm getting this:
Script #php artisan package:discover --ansi handling the post-autoload-dump event returned with error code 255
This is my composer.json file:
{
"name": "laravel/laravel",
"type": "project",
"description": "The Laravel Framework.",
"keywords": [
"framework",
"laravel"
],
"license": "MIT",
"require": {
"php": "^7.1.3",
"fideloper/proxy": "^4.0",
"guzzlehttp/guzzle": "^6.5",
"kitetail/zttp": "^0.6.0",
"laravel/framework": "^7.0",
"laravel/tinker": "^2.0",
"laravel/telescope": "^2.1",
"laravelcollective/html": "^6.0",
"livewire/livewire": "^0.7.4",
"spatie/laravel-html": "^2.24",
"spatie/laravel-permission": "^3.0.0"
},
"require-dev": {
"barryvdh/laravel-debugbar": "^3.2",
"filp/whoops": "^2.0",
"fzaninotto/faker": "^1.4",
"laravel/ui": "^2.0",
"mockery/mockery": "^1.0",
"nunomaduro/collision": "^4.1",
"phpunit/phpunit": "^7.5"
},
"config": {
"optimize-autoloader": true,
"preferred-install": "dist",
"sort-packages": true
},
"extra": {
"laravel": {
"dont-discover": []
}
},
"autoload": {
"psr-4": {
"App\\": "app/"
},
"classmap": [
"database/seeds",
"database/factories"
]
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/"
}
},
"minimum-stability": "dev",
"prefer-stable": true,
"scripts": {
"post-autoload-dump": [
"Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
"#php artisan package:discover --ansi"
],
"post-root-package-install": [
"#php -r \"file_exists('.env') || copy('.env.example', '.env');\""
],
"post-create-project-cmd": [
"#php artisan key:generate --ansi"
]
}
}
I'm confused right now. It even seems that php artisan doesn't do anything in this project. In other projects it's just working fine. Any idea how this could be fixed?
Edit: Some of the answers provided suggestions. I'm getting the following using Laragon:
PS C:\laragon\www\attila> composer update
Updating dependencies (including require-dev)
Package operations: 0 installs, 4 updates, 0 removals
- Updating laravel/framework (v7.0.1 => v7.0.2): Downloading (100%)
- Updating spatie/laravel-permission (3.10.1 => 3.11.0): Downloading (100%)
- Updating laravel/ui (v2.0.0 => v2.0.1): Downloading (100%)
- Updating nunomaduro/collision (v4.1.1 => v4.1.2): Downloading (100%)
Package moontoast/math is abandoned, you should avoid using it. Use brick/math instead.
Writing lock file
Generating optimized autoload files
> #php artisan package:discover --ansi
Script #php artisan package:discover --ansi handling the post-autoload-dump event returned with error code 255
PS C:\laragon\www\attila> php artisan package:discover --ansi
PS C:\laragon\www\attila>
After deleting all the cache in bootstrap & storage/framework folders, still no results.
Running the php artisan --help returns some errors, this gave me a hint where the problem is.
After checking the Upgrade Guide I solved the issue, for me it was:
Changes in App\Exceptions\Handler methods
install require laravel/ui package
For me, it was a very simple error and fix.
The relevant portion of the 7.x Upgrade docs says the following:
Symfony 5 Related Upgrades Likelihood Of Impact: High
Laravel 7 utilizes the 5.x series of the Symfony components. Some
minor changes to your application are required to accommodate this
upgrade.
First, the report, render, shouldReport, and renderForConsole methods
of your application's App\Exceptions\Handler class should accept
instances of the Throwable interface instead of Exception instances:
use Throwable;
public function report(Throwable $exception);
public function shouldReport(Throwable $exception);
public function render($request, Throwable $exception);
public function renderForConsole($output, Throwable $exception);
Relevant file: ./App/Exceptions/Handler.php
Change: convert instances of "Exception" to "Throwable" (editor search and replace)
So, basically, once I put the change in place, 'php artisan' started to work again.
This included the package:discover command in the OP's composer.json (and mine).
I tried putting it back to Exception, and the artisan command would fail to do anything.
Change the occurrences of Exception to Throwable, and everything works. (My application only had the first two functions defined, though.)
So, it pays to pay attention to the documentation.
You must delete old files (cache). This commands should works:
cd bootstrap/cache/
rm -rf *.php
composer update
If you are work on regular user, add sudo before each command.
Try this :
cd bootstrap/cache/
rm -rf *.php
Then composer update again.
After following the upgrade guide in the docs some folks in the Laravel Discord chat guided me to update the Symfony 5 Related Upgrades.
I had to remove telescope (which I'm not using) too.
If you are using Laravel 7 for some reason while your install composer 3.x installed on your system. use following command:
composer require laravel/ui ^2.0

Unable to figure out the series of errors by composer while installing Laravel

For last 3 days, I am trying to install laravel 5.5 in my system(windows 8.1) through composer and getting a series of errors one after other. So I am asking some questions in order to clear my doubts which are still doubted after more than 20-25 hour of research on various blogs and SO.
I have installed php 7 in c:\php.
After that, I have installed composer using composer installer and did nothing after that, like setting PATH on environment setting.
I found that I have to create a composer.json file which I have copied from Github and shown below, but I don't know where to keep this composer.json file so I created this file on C:\Users\MyPC (i.e. my home directory).
{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"type": "project",
"require": {
"php": ">=7.0.0",
"fideloper/proxy": "~3.3",
"laravel/framework": "5.5.*",
"laravel/tinker": "~1.0"
},
"require-dev": {
"filp/whoops": "~2.0",
"fzaninotto/faker": "~1.4",
"mockery/mockery": "0.9.*",
"phpunit/phpunit": "~6.0"
},
"autoload": {
"classmap": [
"database/seeds",
"database/factories"
],
"psr-4": {
"App\\": "app/"
}
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/"
}
},
"extra": {
"laravel": {
"dont-discover": [
]
}
},
"scripts": {
"post-root-package-install": [
"#php -r \"file_exists('.env') || copy('.env.example', '.env');\""
],
"post-create-project-cmd": [
"#php artisan key:generate"
],
"post-autoload-dump": [
"Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
"#php artisan package:discover"
]
},
"config": {
"preferred-install": "dist",
"sort-packages": true,
"optimize-autoloader": true
}
}
Please check the code above if I have committed any mistake.
After that I executed "composer update" command which downloaded a lot of files and placed in C:\Users\MyPC\vendor folder (I think), but throws an error at last which I can't remember.
After that I executed "composer install" command and get this error shown below.
This is my problem and I am not able to figure out what to do.
I have a couple of more doubt:
a - composer create-project --prefer-dist laravel/laravel NAME_OF_PROJECT can also be used to set up new project then why we use composer global require “laravel/installer” and then laravel new NAME_OF_PROJECT method. What are the benefits of using this method.
b - What are the steps to follow after the installation of the composer using the installer for setting up a new laravel project. What are the best practices to structure the project folder?
Please help me. I am learning laravel but don't know how to deal with this composer stuff and installing laravel as most or all of the tutorial starts with creating new project file .they don't teach how to install them.
Ok so a lot of research and try and errors I figured out a way that worked for me. I am using Windows 8.1.
I have installed php 7 in c:\php.
Note : Download php from
http://php.net/downloads.php. Download Non Thread Safe
version in zip format and extract it to the
desired folder (I extracted in C:\php).
After that I have installed composer using composer installer and did nothing after that, like setting PATH on environment setting, Installer will do it for you.
Download Composer Installer from https://getcomposer.org/download/.
After that I have downloaded laravel from github and exctrated to the desired project folder.
Download Laravel latest version from https://github.com/laravel/laravel
After that I ran "composer self-update"command.
After that I ran "composer update"command.
After that I ran "composer global require “laravel/installer”"command. This command will install Laravel Installer.
Now I can go to the project folder directory and run "laravel new myProjectName" command to create new laravel project.

Autoloader does not seem to be updating (Laravel)

I'm new to PHP Laravel. I've added a package using composer: composer require djchen/oauth2-fitbit. It seems that my composer.json did not update the autoloader as i keep getting the following error:
Fatal error: Class 'djchen\OAuth2\Client\Provider\Fitbit' not found in xxx on line 5.
this is what line 5 looks like:
use djchen\OAuth2\Client\Provider\Fitbit;
$provider = new Fitbit([ // line 5
Here is my composer.json (necessary bits)
{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"type": "vcs",
"require": {
"php": ">=5.6.4",
"djchen/oauth2-fitbit": "^1.0",
"laravel/framework": "5.4.*",
"laravel/tinker": "~1.0"
},
"require-dev": {
"fzaninotto/faker": "~1.4",
"mockery/mockery": "0.9.*",
"phpunit/phpunit": "~5.7"
},
"autoload": {
"classmap": [
"database"
],
"psr-4": {
"App\\": "app/",
"djchen\\OAuth2\\Client\\": "src/" // added manually - still does not work
}
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/",
}
},
I've done my research and i've tried composer install, composer update and composer dump-autoload. None of these worked. Any help would be appreciated.
Let's go with the nuclear solution here, your autoload file probably is cached somewhere.
Run following commands:
php artisan clear-compiled
php artisan cache:clear
php artisan config:clear
php artisan optimize
If this doesn't work, try to manually delete all autoload files you can find and run a composer update.
Answering my own question..
I probably should have really emphasised the fact that I'm new to Laravel. I managed to get around this by simply including the autoloader:
include('vendor/autoload.php');
And also calling composer dump-autoload afterwards.

How to use git with Symfony 2?

I installed Symfony 2 with Composer (following the 'master' guides), and it created this .git/config file:
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
[remote "origin"]
fetch = +refs/heads/*:refs/remotes/origin/*
url = git://github.com/symfony/symfony-standard
pushurl = git#github.com:symfony/symfony-standard.git
[branch "master"]
remote = origin
merge = refs/heads/master
[remote "composer"]
url = git://github.com/symfony/symfony-standard
fetch = +refs/heads/*:refs/remotes/composer/*
I don't want to interfere with what Composer did here since I don't know how it works, and I want to be able to update the vendors in the future.
So how do I add my own repository for 'myapp' and commit/push to it? I usually do 'git remote add origin ...' and only work with that, but now there are two repositories in the file, plus the one I need to add.
UPDATE
I installed Symfony2 with this command:
$ php composer.phar create-project symfony/framework-standard-edition myapp
This created myapp/ and installed Symfony2 + dependencies. But now composer.json does not look like it's ready to use for my project, it looks like my project is Symfony2 itself (I think):
{
"name": "symfony/framework-standard-edition",
"description": "The \"Symfony Standard Edition\" distribution",
"autoload": {
"psr-0": { "": "src/" }
},
"require": {
"php": ">=5.3.3",
"symfony/symfony": "2.1.*",
"doctrine/orm": "2.2.*",
"doctrine/doctrine-bundle": "dev-master",
"twig/extensions": "dev-master",
"symfony/assetic-bundle": "dev-master",
"symfony/swiftmailer-bundle": "dev-master",
"symfony/monolog-bundle": "dev-master",
"sensio/distribution-bundle": "dev-master",
"sensio/framework-extra-bundle": "dev-master",
"sensio/generator-bundle": "dev-master",
"jms/security-extra-bundle": "1.1.*",
"jms/di-extra-bundle": "1.0.*"
},
"scripts": {
"post-install-cmd": [
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile"
],
"post-update-cmd": [
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile"
]
},
"config": {
"bin-dir": "bin"
},
"minimum-stability": "dev",
"extra": {
"symfony-app-dir": "app",
"symfony-web-dir": "web"
}
}
Master Guides
http://symfony.com/doc/master/book/installation.html (for the first step, which is downloading symfony, I used the composer command, as shown here: http://symfony.com/download)
http://symfony.com/doc/master/cookbook/workflow/new_project_git.html (this one seems to be outdated, since it says we have to do 'git init', but the git repo is already created by composer)
You can safely remove the .git folder and run git init to initialise your own repo just like #m2mdas suggests.
Composer is not doing anything special here. It just clones the symfony-standard project and then installs its dependencies.
Composer clones the repository but it doesn't need the .git folder to work. In fact I don't think it should be cloning projects by default. Might be they'll fix it in future versions.
Composer uses composer.json file and you should manage all your dependencies with this one file. You can safely edit it to add or remove packages.
Then, to update packages just run:
php composer.phar update
All the packages removed from composer.json will be removed, those you added will be installed. Existing packages will be updated to the latest version.
You should store the generated composer.lock file in your repo to be sure you'll always get the same versions of dependencies when you run:
php composer.phar install
composer.lock is updated when you first run install and with every update command.

Categories