在开发 Laravel package
时,引入了GuzzleHttp
,但是再 new client 时报错:
>>> app('ipconversion')
=> VavoCake\IpConversion\IpConversion {#2824}
>>> app('ipconversion')->convert('183.160.92.159')
PHP Error: Class 'VavoCake/IpConversion/GuzzleHttp/Client' not found in /home/vagrant/Code/packagetest/packages/vavocake/ipconversion/src/Traits/HttpRequestTrait.php on line 20
引用代码:
<?php
namespace VavoCake\IpConversion\Traits;
use GuzzleHttp\Client;
class HttpRequestTrait
{
public function get($ip)
{
$client = $this->getHttpClient([
'base_uri' => config('ipconversion.url')
]);
$response = $client->request('GET', $this->makeParams($ip));
return $response;
}
protected function getHttpClient(array $options)
{
return new Client($options);
}