How can I use a class from a vendor folder in a laravel project

I am trying to enable guzzle http client from a vendor folder and using composer. Here is what I have tried so far.

File Location http: http: vendor/guzzle/guzzle/src/Guzzle/Http/Client.php

In composer.json I included

"autoload": {
    "classmap": [
        "database/seeds",
        "database/factories"
    ],
    "files":["vendor/guzzle/guzzle/src/Guzzle/Http/Client.php"],
    "psr-4": {
        "App\\": "app/"
    }
},

I executed the command composer dumpautoload.

In my controller, I am trying to call an api endpoint like this

use GuzzleHttp\Client;
$client = new Client(); // this line gives error 
$res = $client->get('https://api.fixer.io/latest?symbols=CZK,EURO');

Error Class 'GuzzleHttp\Client' not found

What am I missing here, please help me. Thank you

For a better file structure, here is a screenshot of the file location enter image description here

+4
source share
1 answer

Short version: you are trying to instantiate a class that does not exist. Create the right class and you're done.

: .json, Guzzle . Guzzle PSR , , , , Gzzle, .

Guzzle 3. ,

namespace Guzzle\Http;
/*...*/
class Client extends AbstractHasDispatcher implements ClientInterface
{
        /*...*/
}

guzzle client Guzzle 3 GuzzleHttp\Client. Guzzle\Http\Client.

$client = new \Guzzle\Http\Client;

use Guzzle\Http\Client;
$client = new Client;

.

+6

Source: https://habr.com/ru/post/1691472/


All Articles