Hi guys, I'm following the Video Game aggregator series but am struggling now I've moved on to a single page.
public function show($slug)
{
$game = Http::withHeaders([ /* Use HTTP client with headers of API tokens from .env */
'Client-ID' => env('IGDB_KEY'),
'Authorization' => env('IGDB_AUTH'),
]) ->withBody( /* Get the 12 highest rated games with their name and rating */
'fields name, slug;
where slug=\"$slug\";
limit 1;',
'text/plain'
)
->post('https://api.igdb.com/v4/games')->json();
dump($game);
return view('show');
}
Following the video I run in to this error - cause" => "Mismatched input, double check your input. Common cause is sending " instead of "." - I read about single quoted string variables being handled different by PHP so I also tried this method that is working with some previous variable I had however they are hardcoded.
public function show($slug)
{
$game = Http::withHeaders([ /* Use HTTP client with headers of API tokens from .env */
'Client-ID' => env('IGDB_KEY'),
'Authorization' => env('IGDB_AUTH'),
]) ->withBody( /* Get the 12 highest rated games with their name and rating */
'fields name, slug;
where slug= '.$slug.';
limit 1;',
'text/plain'
)
->post('https://api.igdb.com/v4/games')->json();
dump($game);
return view('show');
}
This returns me the error - "cause" => "Expecting a STRING as input, surround your input with quotes starting at 'maia' expecting {'{', 'f', '(', '[', 'true', 't', 'false', 'null', 'n'" - So I'm not sure on how retrieve game details where the slug matches the slug that is in the URL and is being passed across.
Any help is greatly appreciated.