I am trying to make my sales app send a customer a message with all the purchased items with their prices. The purchased items are stored in the dp, each item with its quantity and price.
I have fetched all the purchased items, but I can't put the items' name and prices into a single sting - which is the message to be send to the customer.
Below is my items array object
$order = App\Order::find($id);
$items = $order->orderItems;
$item = OrderItem::where('order_id', $order->id)->first();
$message = $order->code . " confirmed. ".$order->customer->name ." ". $order->customer->vehicle_plate . " has paid KES ".$order->amount." for ".$item->quantity." ".$item->item->unit->name." of ".$item->item->name." at ".$order->updated_at->format('d/m/Y h:i a');
This message has the first item of the order. I need a single message with all order items.
you can concatenate item data by iterating through the loop
$order = App\Order::find($id);
$items = $order->orderItems;
$item = OrderItem::where('order_id', $order->id)->first();
$message = $order->code . " confirmed. ".$order->customer->name ." ". $order->customer->vehicle_plate . " has paid KES ".$order->amount." for ";
foreach($item as $item_value){
$message .= $item_value->quantity." ".$item_value->item->unit->name." of ".$item_value->item->name;
}
$message .= " at ".$order->updated_at->format('d/m/Y h:i a');
echo $message;
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加