when i use ‘Post or Patch/Put’ for raw json it works fine, but when use form-data ‘Post’ only works and ‘Put/Patch’ doesn’t work.although it shows success:true .
Hey @asadali28032
Without more context of the API you’re using and the expected structure for those methods, it’s tough to give any type of advice here.
What do you mean by doesn’t work? An error? A message returned from the server? Something else?
Please include links to any public documentation and share some visual examples for you’re seeing.
@asadali28032 you are right i am having this issue for a year now i started using ‘POST’ for edit as well
@danny-dainton look at the code i have
route file
Route::put('/makeVisitorDecision', [NotificationController::class, 'makeVisitorDecision']);
controller file
public function makeVisitorDecision(Request $request)
{
try {
$request->validate([
'visitor_id' => 'required|integer',
'action' => 'required|in:approve,reject',
]);
$visitor = VisitorHistory::find($request->visitor_id);
if (!$visitor) {
return response()->json([
'msg' => 'Visitor not found'
], 404);
}
if ($visitor->status !== 'Pending') {
return response()->json([
'msg' => 'Visitor is not in a state to be approved or rejected'
], 422);
}
$visitor->status = $request->action === 'approve' ? 'UserApproved' : 'UserRejected';
$visitor->save();
return response()->json([
'msg' => $request->action === 'approve' ? 'Visitor approved' : 'Visitor rejected'
]);
} catch (\Throwable $th) {
return response()->json([
'msg' => $th->getMessage()
]);
}
}