user15240617
user15240617

Reputation:

Send a dynamic variable with HTTP client API consume Laravel

public function index($word)
    {
        
        $response = Http::withHeaders([
            'app_id' => 'xxxxxxx',
            'app_key' => 'xxxxxxxxxxxxxxxx'
        ])->get('https://od-api.oxforddictionaries.com/api/v2/lemmas/en/{word_id}')->json();
       return $response 
    }

How can I send the variable $word in the {word_id} in this function I Have Tried

(https://od-api.oxforddictionaries.com/api/v2/lemmas/en/{word_id}',['word_id'=>$word]);
GOt error

Upvotes: 0

Views: 215

Answers (1)

Miqayel Srapionyan
Miqayel Srapionyan

Reputation: 587

You can concat it like this get('https://od-api.oxforddictionaries.com/api/v2/lemmas/en/'.$word) or you can use double quotes like this get("https://od-api.oxforddictionaries.com/api/v2/lemmas/en/$word")

Upvotes: 1

Related Questions