2017-12-28 2 views
4

공급 업체 폴더 및 작곡가에서 guzzle http 클라이언트를 포함하려고합니다. 여기에 내가 지금까지 시도한 것이있다. composer.json 파일에서 목구멍 HTTP 클라이언트 파일 vendor/guzzle/guzzle/src/Guzzle/Http/Client.phplaravel 프로젝트의 공급 업체 폴더에있는 클래스를 사용하는 방법

위치는 내가 명령 composer dumpautoload 실행 한

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

포함되어 있습니다. 내 컨트롤러에서

내가이

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

오류 같은 API 엔드 포인트를 호출하는 시도하고 Class 'GuzzleHttp\Client' not found 내가 여기 실종 무엇

이, 저를 도와주세요입니다. 감사. 여기에 더 나은 파일 구조에 대한

는 파일 위치 enter image description here

+0

composer.json에 추가 할 필요가 없습니다. 'composer dumpautoload'를 실행 했습니까 – aynber

+0

config/app.php에 패키지를 등록 했습니까 –

+0

@RahulReghunath 아니요. – sadek

답변

6

짧은 버전의 스크린 샷입니다 : 당신은 존재하지 않는 클래스를 인스턴스화하려는. 올바른 클래스를 인스턴스화하면 모든 것이 설정됩니다.

긴 버전 : Guzzle 작동을 위해 작곡가와 공상 할 필요가 없습니다. Guzzle은 Autoloading을위한 PSR 표준을 준수합니다. Guzz가 작곡가를 통해 가져온 한, 자동 로딩 걱정없이 Guzzle 클래스를 인스턴스화 할 수 있습니다.

언급 한 파일 경로에 따라 like you're using Guzzle 3으로 표시됩니다. 목구멍 3 the class you're trying to include

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

목구멍 클라이언트 클래스에서 구체적으로 보면 GuzzleHttp\Client 없습니다. 그것의 이름은 Guzzle\Http\Client입니다. 그러니

$client = new \Guzzle\Http\Client; 

또는

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

을 시도하고 모든 설정해야합니다.

+1

감사합니다 :) 설명과 설명에 감사드립니다! – sadek

관련 문제