I am trying to make an API call.
If I do this: $url = "url-code.com?param1=value1¶m2=value2&_token=enter-key-here";
I don't get any error.
If I do this: $url = "url-code.com?param1=value1¶m2=value2&_token="+Config::get('app.john_doe_key');
I get an error: 'URI must be a string or UriInterface'
$statusCode = 200;
$url = "url-code.com?param1=value1¶m2=value2&_token="+Config::get('app.john_doe_key');
$client = new Client();
$res = $client->get($url);
//dd($res);
return $res->getBody();
.env
JOHN_DOE_APP_KEY=key
config/app.php
'john_doe_key' => env('JOHN_DOE_APP_KEY'),
All right, based on our discussion in the comments of original question, here's what I would try.
Since everything in it's own works correctly, I would put all of the parameters in their own array:
$parameters = [
'someParam' => 'value',
'someOtherParam' => 'value',
'_token' => Config::get('app.john_doe_key')
];
And use http_build_query()
to correctly format them:
$formattedParameters = http_build_query($parameters);
And finally, build the URL with what I have:
$url = "http://url-code.com?{$formattedParameters}";
You should be having a correctly formatted URL to use with Guzzle at this point.