Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

webfuelcode's avatar

How to pass the id in API call

I tried this but happen nothing

function coin($id)
    {
        $host = config('api_host');
        $key = config('api_key');
        $collection = Http::withHeaders([
            'x-api-host' => $host,
            'x-api-key' => $key
        ])->get('https://localhost/game/', [
            'id' => $id,
        ]);
        return view('coin', ['collection'=>$collection['data']]);
    }

API host is here to get the specific game detail by its ID. Like https://localhost/game/1

How to send id (1 or 2 or 3 or 4...) in the API url...

0 likes
6 replies
Sinnbeck's avatar

But you just append it

->get('https://localhost/game/'. $id)
webfuelcode's avatar

@Sinnbeck Another one here is about the link with id.

@foreach($collection as item)
	{{$item['name']}} <a href="{{route('coin', ............}}">Open</a>
@endforeach

Hoe to pass the id... {{$item['id']}} in this link...

Sinnbeck's avatar

@webfuelcode

@foreach($collection as item)
	{{$item['name']}} <a href="{{route('coin', ['id' => $item['id']])}}">Open</a>
@endforeach
Sinnbeck's avatar

@webfuelcode yes, but you need to change the route to accept the slug then

Assuming the key is slug

@foreach($collection as item)
	{{$item['name']}} <a href="{{route('coin', ['slug' => $item['slug']])}}">Open</a>
@endforeach

Please or to participate in this conversation.