I can't make a youtube link to be dynamic by passing the position of their array's location in the Collection.
First, I make a GET request to an API like this:
public function thps4($id)
{
$id++;
$thps4Videos = Http::get('http://thvid-api.herokuapp.com/videos/game/THPS4/$id/1')->json();
$thps4Video = $thps4Videos[0];
return view ('videos.thps4', compact('thps4Video'));
}
In a forelse I iterate through the information but also I pass this data with a $key variable, and I have an href=""
<a class="relative bottom-4" href="videos/thps4/{{ $key }}">
This URL, it displays something like this: thps4/videos/0 and that should point to the array in the 0 position, and this number changes for other items currently being displayed.
On the end point of this URL I am passing the variable $thps4Video and I use the ID column and insert it on the Youtube URL like this:
"src": "http://www.youtube.com/watch?v={{ $thps4Video['ID'] }}"}],
It is a json object that accepts many properties, one of them being a Youtube link, if more info should be provided do tell please.
I should be able to see a different video everytime I click on a link provided by that href but I always see the same one.
It's a Laravel 8 project and im using VideoJS version 7.11.8 with the Youtube extension (wonderful)
A little bit about the API
This API actually fetches data from Youtube videos and fetches that metadata to it's own endpoint (http://thvid-api.herokuapp.com) so any column that exists here also does on Youtube. They all have a column named "_id", but also one called "ID" which is the ID that corresponds for every video, the former seems to be the id of the array, I think.