php - GuzzleHttp and Laravel - Syntax error - T_String -


i trying use guzzlehttp laravel access api based on user's input.

my set-up far:

$client = new \guzzlehttp\client(); $response = $client         ->get('https://api.postcodes.io/postcodes/'input::get('postcode')); dd($response->getbody()); 

but error being returned is:

fatalerrorexception in cliniccontroller.php line 129: syntax error, unexpected 'input' (t_string)

line 129 https://api.postcodes.io/postcodes/'input::get('postcode')

any why occurring hugely appreciated.

that's simple php error. here's line php complaining about

->get('https://api.postcodes.io/postcodes/'input::get('postcode')); 

you have string

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

immediately followed input::get('postcode'). if you're trying combine these two, you'll want use . operator concatenate strings

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

also, consider -- in production application, you'd want either sanitize or validate input::get('postcode') contains post code before using in url request that. assume try use system maliciously, , never trust user input contain think contains.


Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -