Why "Class 'GuzzleHttp\Client' not found" even after Installing it in Laravel? - php

I've been reading answers from all the questions related to GuzzleHttp\Client but situation is getting worst. I am trying to send E-mail Updates to all of my Application users using Laravel Queues. I don't know what's wrong but Jobs are failing.
I am properly caching the Exceptions and reporting them to laravel.log file. Here is what I am getting when I try to execute queue worker.
[2018-03-23 11:43:06] production.ERROR: Class 'GuzzleHttp\Client' not found {"exception":"[object] (Symfony\\Component\\Debug\\Exception\\FatalThrowableError(code: 0): Class 'GuzzleHttp\\Client' not found at /home/polymath/saio/public_html/vendor/laravel/framework/src/Illuminate/Mail/TransportManager.php:181)
I've already installed GuzzleHttp\Client using composer require guzzlehttp/guzzle. It is successfully installed but still, I am getting the same error.
Even I tried to delete the current application files and clone my whole repository again. Still Facing the same issue. I even tried to clear caches using php artisan cache:clear , php artisan cache:config and php artisan clear-compiled(This made my whole application crash) , php artisan dump-autoload.
I can't find what's wrong but that's all logs say.

It seems you may need an older version of Guzzle to work with Laravel, try using Guzzle 3.x by updating your composer.json like such
"guzzlehttp/guzzle": "~3"
If you wish you can also try to use ~4 and see if Guzzle 4.x will work for you, remember to run composer update and composer dump-autoload after updating your composer.json file.
Update: This info is based on research since Laravel 4 and may be deprecated for Laravel 5.x

use GuzzleHttp\Client;
in your method Add
$client = new Client();

Related

Unable to locate publishable resource when adding sanctum to existing project

The Laravel Sanctum documentation states that to add Sanctum to existing Laravel project one has to:
Require Laravel Sanctum composer require laravel/sanctum
Publish Sanctum's resources to app dir php artisan vendor:publish --provider="Laravel\Sanctum\SanctumServiceProvider"
I'm getting Unable to locate publishable resources. when running (2)
I already tried php artisan clear-compiled and composer dumpautoload in that order
I checked that vendor/laravel/sanctum/src/SanctumServiceProvider.php exists and the boot() method does publishes Sanctum's config and migration
I also checked that SanctumServiceProvider is discovered by autoload by making sure that the source path is listed in autoload_classmap.php
Again, this was an attempt to add Sanctum to an existing Laravel project
Did I miss something?
My setup:
Laravel 8.37
PHP 7.3.9
Composer 2.0.12
I have managed to solve my problem.
Short answer:
After composer require laravel/sanctum do this:
Backup or rename cache/services.php
Remove cache/services.php
Run php artisan. Seems that running artisan in any way will regenerate cache/services.php
After that, continue with the official documentation (publish, migrate, and so on)
Longer explaination
Not entirely sure what is going on. But apparently all discovered service provider is cached in cache/services.php.
I don't know how it's being generated and how service providers get discovered. Googling doesn't yield me any documentation regarding that file (official or otherwise).
I figured I if I add Sanctum's SP to config/app.php (i.e. the documented way of adding service provider) it will get discovered and cached. Apparently that wasn't the case. Removing and regenrating cache/services.php is the only way I found working. After the file was regenerated, Sanctum's SP is listed.
One thing I observe was that this only happens on an existing project (existing as in already being worked on, packages added, config changes and so on). Doesn't happen if I add Sanctum to a fresh project.

Laravel 6: FatalThrowableError: Class 'GuzzleHttp\Client' not found in TransportManager.php

I just updated my application to Laravel 6.
I'm sending email via Mailgun, and in my local environment I've confirmed that everything works perfectly.
But in staging I get the following error:
Symfony\Component\Debug\Exception\FatalThrowableError: Class 'GuzzleHttp\Client' not found in /my/directory/laravel/vendor/laravel/framework/src/Illuminate/Mail/TransportManager.php:193
I've run composer require guzzlehttp/guzzle and triple-checked that it is in the vendor folder and the autoload files on my staging server.
My emails are sent over a queue. I called Guzzle from a controller method and it was found without problems, but for some reason when the queue job runs, the TransportManager can't access it.
Again, in my local homestead environment emails are sent via mailgun with no errors.
I've done artisan cache:clear and artisan config:clear.
I can't think of anything else to try. Any idea what could be causing the problem?
Figured it out... Laravel queues use some code-caching magic I wasn't aware of. So my queue was using old code from before I ran composer require guzzlehttp/guzzle.
To solve the problem I had to run php artisan queue:restart.
Then I waited for my scheduler to rerun php artisan queue:work and my email is now sent as expected.

Interface 'Monolog\ResettableInterface' not found when running a new project

Whenever I try to run any command related to php artisan or composer this error shows up:
PHP Fatal error: Interface 'Monolog\ResettableInterface' not found in path\to\project\root\vendor\monolog\monolog\src\Monolog\Logger.php on line 28
I open the file, and it points me to :
class Logger implements LoggerInterface, ResettableInterface
I try to find the Logger interface and it's there.
I really can't find any other solutions and the ones recommended here by SO are outdated.
I use laravel 5.7 running composer version 1.8.0 on a xampp server with PHP 7.2.10 on Windows 10
Please feel free to ask more questions and I'll try to answer them without ruining my NDA.
Update: it works now thanks to that one person who answered.
If anyone needs this solution, you can do what Saumini Navaratnam suggested; removing the vendor folder and running composer update on the root folder. I, myself found another solution that might work and it is: running composer update --no-dev as the ResettableInterface came from a dev dependency. Weird, but it works fine now.
Again this works only on Laravel 5.7, at least for now.

Fatal Error: Class 'Pheanstalk\Pheanstalk' not found

On my API I wanted to change queue drivers. I wanted to switch from Beanstalkd to Redis.
So in my composer.json I changed my dependencies "pda/pheanstalk": "^3.0" to "predis/predis": "~1.0". Then I went to Laravel Forge, added a new Queue Worker which looks like this:
I updated my .env file: QUEUE_DRIVER=redis and ran composer update. After that I tried to fire a notification (with email), the notification implements the ShouldQueue interface and uses the Queueable trait. The notification was send with success (over the queue as well).
At that moment I was happy, but wait... I check my Sentry issues and saw the following error:
Fatal Error: Class 'Pheanstalk\Pheanstalk' not found in vendor/laravel/framework/src/Illuminate/Queue/Connectors/BeanstalkdConnector.php in connect at line 21.
At this moment the bug/issues occurs around 200 times a minute.
What I tried:
Remove all failed jobs from queue
Restart the server
Even installing the pda/pheanstalk package over composer again.
So at the moment I've the pda/pheanstalk installed but don't have the beanstalkd queue worker running and I'm still getting the Class 'Pheanstalk\Pheanstalk' not found error.
My best guess is that when I removed the beanstalkd queue worker and removed the package with composer, their was a job running in the queue worker and now it's retrying that job over and over. But of course I could be totally wrong.
Any ideas on what is going wrong here?
EDIT
I've now deleted my site from Forge, checked if the code was deleted. In Sentry the error is still being logged.. The project doesn't even exists on the server anymore.
Sounds like you havent restarted the queue to use the new settings?
Log into the server and run php artisan queue:restart
The other thing - did you have Supervisor or something already running the older queue config? If so - that could be restarting the older queue.
As official laravel documentation, Please install the latest version of Beanstalkd
Beanstalkd: pda/pheanstalk ~4.0
For more info, Please check this
https://laravel.com/docs/9.x/queues#other-driver-prerequisites
Did you register Pheanstalk\Pheanstalk within your config/app.php file?
Usually that's the case, Laravel won't see any dependencies that were not registered.
Inside of array containing configuration for your app, find `providers', and put namespace of given class inside that array.
Make sure you that you remove any references to this class in conig/app.php as well as run composer dump-autoload.
You may want to do a global search for this class in your app to make sure it's gone. Lastly, delete the vendor folder, if it's still there.
Install pheanstalk as a dependency with composer:
composer require pda/pheanstalk
In PHP file
use Pheanstalk\Pheanstalk;

laravel command not found while using laravel command

I've recently installed composer and also installed laravel installer from composer from the commmand line just like they said in laravel documentation.
But when I used the laravel command on the command line, it show error:
sh.exe": laravel: command not found
I also added environment variable in the path variable.
~/.composer/vendor/bin
But still the same error occurs while using the laravel command.
I'm a laravel newbie and I'm stuck in laravel installation.I've searched lot of times but still could not get the solution. I've read lot of users' questions with the same problem and used their solutions but still could not fix this.
Your path /c/xampp/php:~/.composer/vendor/bin is definitly wrong. Either you have to fix it (should be something like C:/{path_to_your_composer_directory}) or you can simply use composer create-project laravel/laravel --prefer-dist to install a new laravel project.
I would go with the 2nd option, because you don't have to configure something else.
On windows system, please remove . from path (just before .Composer)

Categories