Search code examples
phplaravelhttp-redirectlumen

PUT, DELETE redirecting with Lumen / Laravel


I have a simple code like this in my "web.php" attempting to redirect a PUT request to another external "PUT" endpoint, the issue is that it is only redirecting it to the "GET" endpoint and not to the "PUT".

$router->put('endpoint/{id}', function ($id) use ($router) {
        return redirect()->to( URL_address/newpoint/'.$id);
    });

So how can I redirect it to the "PUT" ?


Solution

  • Such redirect might be possible with status code 307. However, PUT is commonly used by client software, and no one honors 307.

    So instead you could use the Laravel 'HTTP Client' for this where you can do something like this:

    $response = Http::put('http://example.com/endpoint/'.$id, request()->all());
    
    return $response->body();
    

    You can find more details on how to use the HTTP Client here: https://laravel.com/docs/http-client#request-data