0

This is my route file:

Route::get('/','guzzle@guzzle'); 

And this is my controller class:

use App\Http\Requests;
use GuzzleHttp\Client;

class guzzle extends Controller
{
    public function guzzle(){

    $client = new GuzzleHttp\Client();
    $request = $client->head('http://www.amazon.com');

    $response = $request->send();
    echo $response->getContentLength();

It gave me the following error message in my browser:

FatalErrorException in guzzle.php line 17:
Class 'App\Http\Controllers\GuzzleHttp\Client' not found

I don't know how to fix this issue. Who can help me?

Al Foиce ѫ
  • 4,195
  • 12
  • 39
  • 49
abraham foto
  • 437
  • 6
  • 16
  • Instead of `use GuzzleHttp\Client;`, use `use \GuzzleHttp\Client;`. What you are currently doing is calling GuzzleHttp as if it is in the same namespace which it is not. – bytesarelife Oct 09 '16 at 13:00
  • i tried that one too the error that iam getting looks like this::::::; cURL error 7: Failed to connect to www.amason.com port 443: Timed out (see http://curl.haxx.se/libcurl/c/libcurl-errors.html) – abraham foto Oct 09 '16 at 13:23
  • 1
    `Failed to connect to www.amason.com` Are you sure it's going to `www.amazon.com` and not `www.amason.com` ? – bytesarelife Oct 09 '16 at 13:27
  • Sorry my typo error..... It actually failed to connect to any website. even my school website ::::: i get always this error :::::::cURL error 60: SSL certificate problem: unable to get local issuer certificate (see http://curl.haxx.se/libcurl/c/libcurl-errors.html) – abraham foto Oct 09 '16 at 13:40
  • Sorry my typo error..... It actually failed to connect to any website. even my school website ::::: i get always this error :::::::cURL error 60: SSL certificate problem: unable to get local issuer certificate (see http://curl.haxx.se/libcurl/c/libcurl-errors.html) – abraham foto Oct 09 '16 at 13:41
  • As the error mentions, this is a certificate problem. Head over to [this question](http://stackoverflow.com/q/28858351/6270112) to solve this. – bytesarelife Oct 09 '16 at 13:47
  • Tnx i will try that one – abraham foto Oct 09 '16 at 14:25
  • @bytesarelife `use GuzzleHttp\Client;` is perfectly fine. It's `$client = new GuzzleHttp\Client();` that'd be a problem - it can be just `new Client` because of the `use`. – ceejayoz Oct 12 '16 at 14:04
  • @ceejayoz `Class 'App\Http\Controllers\GuzzleHttp\Client' not found`. Clearly namespace prefixing a problem there because it's trying to find the `Client` in the same namespace i.e: `App\Http\Controllers` – bytesarelife Oct 12 '16 at 16:58
  • @bytesarelife That error is caused by the `$client = new GuzzleHttp\Client` line. Not the `use GuzzleHttp\Client` one. Yes, OP has an issue with namespacing. No, "Instead of use GuzzleHttp\Client;, use use \GuzzleHttp\Client;" will not fix it. – ceejayoz Oct 12 '16 at 17:50
  • @ceejayoz Of course, just namespace fix will not resolve the issue. I was just pointing it as one of the exceptions. – bytesarelife Oct 12 '16 at 18:08

2 Answers2

2

Once you have imported the class:

use GuzzleHttp\Client;

You should not type the full class namespace while instantiating it:

wrong: new GuzzleHttp\Client();

right: new Client();

hamedmehryar
  • 414
  • 2
  • 10
0

You can also get rid of the namespace prefixing with this:

$client = new \GuzzleHttp\Client();
Taha Paksu
  • 15,371
  • 2
  • 44
  • 78