Multiple records are created for same order
I am using Database Transaction
for a endpoint where staff can accept the order perform certain operation thereafter. I don’t want same order to be assigned to different staff.I used Database transaction
for that but the problem is multiple staff are assigned to same order when the staff accepts the order at same time.
The sample code is provided below:
try {
$message = [
"status_validation" => "Input status must have value assigned",
"unique" => "Order is assigned to other driver"
];
$this->validate($request, [
"restaurant_id" => 'required|integer|min:1',
"order_id" => 'required|integer|min:1|unique:driver_order,order_id',
"status" => 'required|status_validation'
], $message);
} catch (Exception $ex) {
return response()->json([
"status" => "422",
"message" => $ex->response->original
], 422);
}
try {
DB::beginTransaction();
$assignOrderToDriver = $this->driverOrder->createDriverOrder($request);
DB:commit();
return response()->json([
"status" => "200",
"message" => "Order has been sucessfully assigned."
], 200);
}
catch (Exception $ex) {
return response()->json([
"status" => "500",
"message" => $ex->getMessage()
], 500);
}
This issue is really creating problem in my project.Am i doing something wrong here ? Thank you.
from Laravel Questions and Answers https://laravelquestions.com/php/multiple-records-are-created-for-same-order/
via Lzo Media
No comments:
Post a Comment