Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

danultimate's avatar

PUT http://127.0.0.1:8000/api/suppliers/ 405 (Method Not Allowed)

Im working on a code that should add or update new "suppliers"

after filling the form Im getting the error 405

Here is my update function of the controller.

public function update(Request $request, Suppliers $suppliers) { if ($suppliers === null) { return response()->json(['error' => 'Supplier not found'], 404); }

$validator = Validator::make(
    $request->all(),
    [

    ]
);

if ($validator->fails()) {
    return response()->json(['errors' => $validator->errors()], 403);
} else {
    $params = $request->all();
    $suppliers->proveedor = $params['proveedor'];
    $suppliers->contacto = $params['contacto'];
    $suppliers->telefono = $params['telefono'];
    $suppliers->email = $params['email'];
    $suppliers->pais = $params['pais'];
    $suppliers->direccion = $params['direccion'];
    $suppliers->calidad = $params['calidad'];
    $suppliers->pedidos = $params['pedidos'];
    $category->save();
}

return new SuppliersResource($suppliers);

}

/**
 * Remove the specified resource from storage.
 *
 * @param  \App\Laravue\Models\Suppliers  $suppliers
 * @return \Illuminate\Http\Response
 */
public function destroy(Suppliers $suppliers)
{
    //
}

}

0 likes
5 replies
tykus's avatar

That is the store action.

The update action will get the id of the Supplier record that you want to update from the request such as suppliers/{supplier}, so the method accepts a second argument e.g.

public function store(Request $request, \App\Supplier $supplier)
{
    // ...

In this example, because we have a wildcard {supplier} and a matching argument to the function $supplier that has a \App\Supplier typehint to the underlying model, we can leverage Route Model binding (i.e. the query to find the correct record is done automatically.

danultimate's avatar

I get Undefined index: proveedor when I try with the ID

tykus's avatar

Well, thats a different issue. You (probably) are hitting your update method now.

I answered a question from you yesterday where I explained why proveedor was undefined. Assuming you have a similar request payload you need to handle that update method in the same way I suggested yesterday.

Please or to participate in this conversation.