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

Asim_Shabbir's avatar

PUT is not working in API.

PUT is not working in laravel API. I create the API and call in postman and it is not working. I am not using .blade file because i use this api for mobile also. Code for route is

Route::controller(DistrictController::class)->group(function () { Route::get('districts', 'index'); Route::post('district', 'store'); // Route::get('district/{id}', 'show'); Route::put('district/{id}', 'update'); //Route::delete('district/{id}', 'destroy'); });

0 likes
12 replies
Sinnbeck's avatar

Thats not a lot to go by. If you want help we need more information and some code

Asim_Shabbir's avatar

@Sinnbeck what information you required. In controller i write the following code public function update(Request $request, $id) { // $request->validate([ 'name' => 'required|string|max:255', 'district' => 'required|integer', ]);

    $district = District::find($id);
    echo($district);
    $district->name = $request->name;
    $district->save();

    return response()->json([
        'status' => 'success',
        'message' => 'District updated successfully',
        'data' => $district,
    ]);
}
Sinnbeck's avatar

You can format your code by adding ````on the line before and after the code

What error are you getting ? Which file is the route in? api.php or web.php ?

Asim_Shabbir's avatar

@Sinnbeck getting message The / method is not supported for route PUT. Supported methods: GET, HEAD.

Sinnbeck's avatar

@Asim_Shabbir Can you post a screenshot of how you set up postman? You can upload it to imgur and post a link

Sinnbeck's avatar

@Asim_Shabbir That does not matter. Just take a screenshot and upload it to imgur.

Also you still havent answered my question of which file the routes are in ?

Asim_Shabbir's avatar

@Ben Taylor it's a backend api not call from front end (.blade) file. i just call from postman. In future i use this api from react.

Please or to participate in this conversation.