PUT request values are empty

Posted 1 year ago by russellwwest

I am using Lumen for my API. I have a PUT method for updating a product. However, the data is not available in the request object. Why is that? I've seen a few mentions of having to "fool" it by adding _method = put

Surely for an API framework, PUT should work out the box? or am i not understanding?

Thanks

$router->post('/products', '[email protected]');
$router->get('/products', '[email protected]');
$router->put('/products/{id}', '[email protected]');
$router->get('/products/{id}', '[email protected]');

controller:

public function update($id, Request $request)
    {
        $product = $this->productService->editProduct($id, $request);
        if (! $product) {
            return response()->json(['success' => false], 500);
        } else {
            return response()->json(['success' => true], 200);
        }
    }

service

public function editProduct($id, $request)
    {
        $product = Product::find($id);
        $product->name = $request->input('name');
        $product->description = $request->input('desc');
        if ($product->save()) {
            return true;
        } else {
            return false;
        }
    }

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.