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');
});
Thats not a lot to go by. If you want help we need more information and some code
@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,
]);
}
@Asim_Shabbir Is the routes in web.php or api.php? What error are you gettiing?
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 ?
@Sinnbeck getting message
The / method is not supported for route PUT. Supported methods: GET, HEAD.
@Asim_Shabbir Can you post a screenshot of how you set up postman? You can upload it to imgur and post a link
@Sinnbeck
no option to the image. i am using locally. It is not deployed on any server.
@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 looks like your method and route are back to front??
@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 sign in or create an account to participate in this conversation.