GuzzleHttp 和 Laravel - 语法错误 - T_String

GuzzleHttp and Laravel - Syntax error - T_String

我目前正在尝试将 GuzzleHttp 与 Laravel 结合使用,以根据用户的输入访问 API。

我目前的设置:

$client = new \GuzzleHttp\Client();
$response = $client
        ->get('https://api.postcodes.io/postcodes/'Input::get('postcode'));
dd($response->getBody());

但返回的错误是:

FatalErrorException in ClinicController.php line 129: syntax error, unexpected 'Input' (T_STRING)

第 129 行是 https://api.postcodes.io/postcodes/'Input::get('postcode')

对于为什么会发生这种情况的任何帮助,我们将不胜感激。

尝试如下:

$client = new \GuzzleHttp\Client();
 $response = $client
        ->get('https://api.postcodes.io/postcodes/'.Input::get('postcode'));
 dd($response->getBody());

这是一个简单的 PHP 错误。这是 PHP 抱怨

的行
->get('https://api.postcodes.io/postcodes/'Input::get('postcode'));

你有一个字符串

'https://api.postcodes.io/postcodes/'

紧接着是 Input::get('postcode')。如果您尝试将这两者结合起来,您需要使用 . 运算符来连接字符串

 'https://api.postcodes.io/postcodes/' . Input::get('postcode')

此外,需要考虑的事项 - 在生产应用程序中,您需要在 [=27= 】 那样的要求。始终假设有人会尝试恶意使用您的系统,永远不要相信用户输入会包含您认为包含的内容。