How can i get api data with params [Laravel]

here is my controller code:

public function tournaments() {
        $data = 0;
        $response = Http::withHeaders(
            [
                'x-rapidapi-host'=> 'uxxxx',
                'x-rapidapi-key'=> 'asdfasdfas',
            ]
    )->get('https://unibet.p.rapidapi.com/competitions-by-sport/football');
return $response;
}

and response message received: {"message":"Missing required parameters"}

How can i add parameters to these code? for exmpl: params: {sport: 'football'},

And maybe someone could share a tutorial video on how to work with the API LARAVEL?


Solution 1:

If you're talking about query parameters, that's what you're looking for: https://laravel.com/docs/8.x/http-client#get-request-query-parameters

When making GET requests, you may either append a query string to the URL directly or pass an array of key / value pairs as the second argument to the get method

Here's an example of what it would look like:

public function tournaments() {
    $data = 0;
    $response = Http::withHeaders(
        [
            'x-rapidapi-host'=> 'uxxxx',
            'x-rapidapi-key'=> 'asdfasdfas',
        ]
    )->get('https://unibet.p.rapidapi.com/competitions-by-sport', [
        'sport' => 'football'
    ]);
    return $response;
}