How to pass id parameter using php laravel?

  guzzle, laravel, parameters, php

I want to pass the id from the controller to route but I’m having trouble with it. I am a newbie at this so I would really appreciate your help!

Controller:

public function fetchVideo(Request $request)
{
    $client = new Client();
    $input = $request->all();

    $headers = [
        'Authorization' => 'Bearer '.$input['token'],
        'Content-type' => 'application/json',
        'Accept' => 'application/json'
    ];

    $params = [
        'id' => $input['id'],
        'fields' => $input['fields']
    ];

    $response = $client->request ('GET', 'https://api.dailymotion.com/video/{id}', [
        'headers' => $headers,
        'query' => $params
    ]);

    return json_decode($response->getBody(), true);
}

Route:

Route::post('/video/{id}', '[email protected]');

Source: Ask PHP

LEAVE A COMMENT