How to put values of objects from an array into a string

Slim Gera

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.

Amit Sharma

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]

編集
0

コメントを追加

0

関連記事

分類Dev

How to put a string into an array

分類Dev

Find Numeric Values among string from Array of Objects and do calculation

分類Dev

How to get the combination of array values from nested arrays in an array of objects

分類Dev

How to use reduce to retrieve values from deep nested array objects

分類Dev

Paste values from array into string

分類Dev

How to get all values of objects inside array

分類Dev

Javascript: extract objects from inside an array of objects, and put them into a new array

分類Dev

How to get unique an array of objects back from a complex an array of objects?

分類Dev

Sorting array of objects by string vs numeric values behaving differently

分類Dev

Access (and count) just object values from Postgres JSONB array of objects

分類Dev

Fetch unique values from array of objects based on dynamically passed property

分類Dev

How to remove duplicates objects from array in javascript?

分類Dev

How to get an Array of Objects from Firestore in Swift?

分類Dev

How to extract a property from array of objects and slice it?

分類Dev

Put all values of dict in an array

分類Dev

How to check character values on a String array?

分類Dev

How can I print values inside an array made from a string? (Explode)

分類Dev

How to loop through multiple Objects and compare key values to string

分類Dev

Java array values being put into wrong array

分類Dev

How to put some array elements from the middle to last in Javascript

分類Dev

How to put value from array to Zingchart.js

分類Dev

How to Put Thread into Array

分類Dev

How to get a particular attribute from an array of array objects?

分類Dev

How to change json data format from array to array of objects with javascript?

分類Dev

How to get hex values from string?

分類Dev

How to get certain values from string

分類Dev

How to remove duplicate values from an array in PHP

分類Dev

How to remove duplicate values from an array in PHP

分類Dev

How to create instances from Array values

Related 関連記事

  1. 1

    How to put a string into an array

  2. 2

    Find Numeric Values among string from Array of Objects and do calculation

  3. 3

    How to get the combination of array values from nested arrays in an array of objects

  4. 4

    How to use reduce to retrieve values from deep nested array objects

  5. 5

    Paste values from array into string

  6. 6

    How to get all values of objects inside array

  7. 7

    Javascript: extract objects from inside an array of objects, and put them into a new array

  8. 8

    How to get unique an array of objects back from a complex an array of objects?

  9. 9

    Sorting array of objects by string vs numeric values behaving differently

  10. 10

    Access (and count) just object values from Postgres JSONB array of objects

  11. 11

    Fetch unique values from array of objects based on dynamically passed property

  12. 12

    How to remove duplicates objects from array in javascript?

  13. 13

    How to get an Array of Objects from Firestore in Swift?

  14. 14

    How to extract a property from array of objects and slice it?

  15. 15

    Put all values of dict in an array

  16. 16

    How to check character values on a String array?

  17. 17

    How can I print values inside an array made from a string? (Explode)

  18. 18

    How to loop through multiple Objects and compare key values to string

  19. 19

    Java array values being put into wrong array

  20. 20

    How to put some array elements from the middle to last in Javascript

  21. 21

    How to put value from array to Zingchart.js

  22. 22

    How to Put Thread into Array

  23. 23

    How to get a particular attribute from an array of array objects?

  24. 24

    How to change json data format from array to array of objects with javascript?

  25. 25

    How to get hex values from string?

  26. 26

    How to get certain values from string

  27. 27

    How to remove duplicate values from an array in PHP

  28. 28

    How to remove duplicate values from an array in PHP

  29. 29

    How to create instances from Array values

ホットタグ

アーカイブ