swagster
swagster

Reputation: 165

Fatal Error trying to use GuzzleHttp in Laravel 5.2

I'm trying to create a POST request using Laravel 5.2 and GuzzleHttp Client. I've successfully installed GuzzleHttp with Laravel but it just keeps repeating an error.

Fatal error: Call to undefined function App\Http\Controllers\API\Client()

Here is my code.

<?php

namespace App\Http\Controllers\API;

use Closure;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\API\APIConfiguration;
use App\Http\Controllers\Controller;
use GuzzleHttp\Client;

class APIController extends Controller {

  public function __construct(Request $request){
    $this->request = $request;
  }

  public function doShardDetails(Request $request) {
    $APIConfig = new APIConfiguration();
    $client = Client();
    $json = $APIConfig->jsonTemplate("Method");

    $request = $client->post("IP:PORT", $json);

    return $request;
  }

}

I've been trying to fix this for hours, nothing on the internet. :(

Upvotes: 0

Views: 1400

Answers (2)

Pavel Krasnoperov
Pavel Krasnoperov

Reputation: 186

You have a typo:

$client = Client();

You should create a new object:

$client = new Client();

Upvotes: 5

Tiep Phan
Tiep Phan

Reputation: 12596

Fatal error: Call to undefined function App\Http\Controllers\API\Client()

you need import Client class right way - with it own namespace, because namespace App\Http\Controllers\API do not have class name Client

Upvotes: 0

Related Questions