Business Client need Web Development
Contact person: Business Client
Phone:Show
Email:Show
Location: Bengaluru, India
Budget: Recommended by industry experts
Time to start: As soon as possible
Project description:
"class OrderController extends Controller
{
public function place(Request $request)
{
$request->validate([
'token'=>'required|string',
'items'=>'required|array|min:1',
'items.*.id'=>'required|integer|exists:dishes,id',
'items.*.qty'=>'required|integer|min:1',
]);
$table = RestaurantTable::where('token',$request->token)->firstOrFail();
$restaurant = $table->restaurant;
$items = collect($request->items);
$dishIds = $items->pluck('id')->toArray();
$dishes = Dish::whereIn('id',$dishIds)->get()->keyBy('id');
$subtotal = 0; $tax = 0;
$orderItems = [];
foreach($items as $it){
$dish = $dishes[$it['id']];
if(!$dish->available) return response()->json(['error'=>'Dish not available'],422);
$lineSubtotal = $dish->price * $it['qty'];
$lineTax = round($lineSubtotal * ($dish->tax_percent/100),2);
$subtotal += $lineSubtotal;
$tax += $lineTax;
$orderItems[] = [
'dish_id'=>$dish->id,
'name'=>$dish->name,
'unit_price'=>$dish->price,
'quantity'=>$it['qty'],
'tax_amount'=>$lineTax,
'total'=>$lineSubtotal + $lineTax,
'instructions'=>$it['instructions'] ?? null
];
}
$total = $subtotal + $tax;
$uuid = Str::uuid()->toString();
DB::transaction(function() use($restaurant,$table,$orderItems,$subtotal,$tax,$total,$uuid,&$order){
$order = Order::create([
'restaurant_id'=>$restaurant->id,
'restaurant_table_id'=>$table->id,
'uuid'=>$uuid,
'subtotal'=>$subtotal,'tax'=>$tax,'total'=>$total,
'status'=>'pending'
]);
foreach($orderItems as $oi) $order->items()->create($oi);
});
event(new OrderPlaced($order));
return response()->json(['success'=>true,'uuid'=>$order->uuid]);
}
}" (client-provided description)
Matched companies (2)

Crystal Infoway
