How to pass id parameter using php laravel?

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}', 'AppHttpControllers<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d9bdb8b0b5a0b4b6adb0b6b79ab6b7adabb6b5b5bcab99bfbcadbab18fb0bdbcb6">[email protected]</a>');

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

public function fetchVideo(Request $request, $id) // <- {id} parameter in the route
{
   ...
   $response = $client->request('GET', "https://api.dailymotion.com/video/{$id}", [...])
   ...
}


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x