I'm fetching data from the imdb api and when i try to display the data in a blade view I'm facing a lot of errors.
probably because I'm not sure what is the response I'm getting from the api.
please bare with me and thanks in advance for taking the time to read through my question.
so here are some of the available example responses from the api:
{
"d": [
{
"i": {
"height": 1500,
"imageUrl": "https://m.media-amazon.com/images/M/MV5BYTRiNDQwYzAtMzVlZS00NTI5LWJjYjUtMzkwNTUzMWMxZTllXkEyXkFqcGdeQXVyNDIzMzcwNjc@._V1_.jpg",
"width": 1102
},
"id": "tt0944947",
"l": "Game of Thrones",
"q": "TV series",
"rank": 36,
"s": "Emilia Clarke, Peter Dinklage",
"v": [
{
"i": {
"height": 720,
"imageUrl": "https://m.media-amazon.com/images/M/MV5BZTg4YzdjNTctNDg5Mi00ZmU1LTkzOWEtNmMyNDBjZjNhNTJiXkEyXkFqcGdeQXRyYW5zY29kZS13b3JrZmxvdw@@._V1_.jpg",
"width": 1280
},
"id": "vi59490329",
"l": "Official Series Trailer",
"s": "3:19"
},
{
"i": {
"height": 1080,
"imageUrl": "https://m.media-amazon.com/images/M/MV5BMTljMTZmNDUtNTEzNy00NDgyLTk2N2QtOTI3MGQyNWE0MTI5XkEyXkFqcGdeQWplZmZscA@@._V1_.jpg",
"width": 1920
},
"id": "vi1097842713",
"l": "The 8 Most Surprising Moments From \"Game of Thrones\" to Rewatch",
"s": "3:39"
},
{
"i": {
"height": 720,
"imageUrl": "https://m.media-amazon.com/images/M/MV5BMTg0ODM4NTc3OV5BMl5BanBnXkFtZTgwODAwODE1OTE@._V1_.jpg",
"width": 1280
},
],
"q": "game of thr",
"v": 1
}
I have tried to display the data in my blade view using a couple of ways the latest way I'm trying is this, blade.php:
@foreach ($data as $item)
{{$item['d']}}
@endforeach
I'm getting this as a response:
{"data":{"d":[{"i":{"height":4096,"imageUrl":"https://m.media-amazon.com/images/M/MV5BMTg4NDA1OTA5NF5BMl5BanBnXkFtZTgwMDQ2MDM5ODE@.V1.jpg","width":2764},"id":"tt2582782","l":"Hell or High Water","q":"feature","qid":"movie","rank":1332,"s":"Chris Pine, Ben Foster","y":2016},{"i":{"height":755,"imageUrl":"https://m.media-amazon.com/images/M/MV5BMjM5ODQ5Nzc3OF5BMl5BanBnXkFtZTgwOTQzMzM4NjE@.V1.jpg","width":509}
the function in my Controller is this :
public function api(Request $request)
{
$userInput = $request->input();
$response = Http::withHeaders(
[
"x-rapidapi-host"=> "xxxxxxxxx",
"x-rapidapi-key"=> "xxxxxxxxxxx",
]
)->get("https://imdb8.p.rapidapi.com/auto-complete?q=",$userInput)->json();
return json_encode(array('data'=>$response));
}
I have also tired:
return view('view',['data'=>$response]);
but got different errors like:
Illegal offset type.
and tried other ways as well but also didn't succeed.
what I'm I missing?? please help.