我正在尝试将以下数据数组结构化到刀片文件中:
array:6 [▼
"email" => "client_2.mage@webamazingapps.com"
"name" => "Client Deux"
"title" => "1"
"firstname" => "Deux"
"lastname" => "Client"
"\x00*\x00items" => array:4 [▼
0 => {#1685 ▼
+"laboratory": "Cuisine"
+"serving_persons": null
+"desserttextmessage": null
+"dessertdecorchocolateID": "Décoration chocolat et fruits souhaitée"
+"dessertdecorflowerID": "Décoration petites fleurs souhaitée"
+"product_type": "Pain-surprise"
+"product_name": "Mélangé"
+"portions": "100"
+"weight": "2.5 Kg"
+"assortment_1": "Foie gras"
+"assortment_2": "Gruyère"
+"assortment_3": "Jambon"
+"assortment_4": "Jambon cru"
+"color": "Bleu"
+"productprice": "89.00"
+"productaddfee": "5.00"
+"subtotal": "94.00"
}
1 => {#1688 ▼
+"laboratory": "Pâtissier"
+"serving_persons": "2-3 pers."
+"desserttextmessage": "Inscription"
+"dessertdecorchocolateID": "Décoration chocolat et fruits souhaitée"
+"dessertdecorflowerID": "Décoration petites fleurs souhaitée"
+"product_type": "Gâteaux"
+"product_name": "Chocolat"
+"portions": null
+"weight": null
+"assortment_1": null
+"assortment_2": null
+"assortment_3": null
+"assortment_4": null
+"color": null
+"productprice": "19.00"
+"productaddfee": "5.00"
+"subtotal": "24.00"
}
2 => {#1692 ▼
+"laboratory": "Boulanger"
+"serving_persons": "2 pers. | 16 cm"
+"desserttextmessage": "Inscription Tarte"
+"dessertdecorchocolateID": "Décoration chocolat et fruits souhaitée"
+"dessertdecorflowerID": "Décoration petites fleurs souhaitée"
+"product_type": "Tarte"
+"product_name": "Tarte fraises"
+"portions": null
+"weight": null
+"assortment_1": null
+"assortment_2": null
+"assortment_3": null
+"assortment_4": null
+"color": null
+"productprice": "11.00"
+"productaddfee": "5.00"
+"subtotal": "16.00"
}
3 => {#1690 ▼
+"laboratory": "Boulanger"
+"serving_persons": "2 pers. | 16 cm"
+"desserttextmessage": "Inscription Tarte-fine"
+"dessertdecorchocolateID": "Décoration chocolat et fruits souhaitée"
+"dessertdecorflowerID": "Décoration petites fleurs souhaitée"
+"product_type": "Tarte-fine"
+"product_name": "Pommes"
+"portions": null
+"weight": null
+"assortment_1": null
+"assortment_2": null
+"assortment_3": null
+"assortment_4": null
+"color": null
+"productprice": "13.00"
+"productaddfee": "5.00"
+"subtotal": "18.00"
}
]
]
我知道如何获取数组的前5列(数组:6):
{{$content['email']}}
{{$content['name']}}
{{$content['title']}}
{{$content['lastname']}}
{{$content['firstname']}}
但是我不知道如何开始将我的四个产品(数组:4)放入这样的行中:
如果“实验室” =“烹饪”:
+"laboratory": "Cuisine"
+"serving_persons": null
+"desserttextmessage": null
+"dessertdecorchocolateID": "Décoration chocolat et fruits souhaitée"
+"dessertdecorflowerID": "Décoration petites fleurs souhaitée"
+"product_type": "Pain-surprise"
+"product_name": "Mélangé"
+"portions": "100"
+"weight": "2.5 Kg"
+"assortment_1": "Foie gras"
+"assortment_2": "Gruyère"
+"assortment_3": "Jambon"
+"assortment_4": "Jambon cru"
+"color": "Bleu"
+"productprice": "89.00"
+"productaddfee": "5.00"
+"subtotal": "94.00"
标签和数据应显示如下:
laboratory | product_type | product_name | portions | weight | assortment_1 | assortment_2 | assortment_3 | assortment_4 | color | productprice | productaddfee | subtotal
Cuisine | Pain-surprise | Mélangé | 100 | 2.5 Kg | Foie gras | Gruyère | Jambon | Jambon cru | Bleu | 89.00 | 5.00 | 94.00
由于不属于“实验室” =“烹饪”,因此不会显示“服务人员”,“甜点文本消息”,“甜点巧克力”,“甜点花卉ID”列。
如果“ laboratory” =“Pâtissier”:
+"laboratory": "Pâtissier"
+"serving_persons": "2-3 pers."
+"desserttextmessage": "Inscription"
+"dessertdecorchocolateID": "Décoration chocolat et fruits souhaitée"
+"dessertdecorflowerID": "Décoration petites fleurs souhaitée"
+"product_type": "Gâteaux"
+"product_name": "Chocolat"
+"portions": null
+"weight": null
+"assortment_1": null
+"assortment_2": null
+"assortment_3": null
+"assortment_4": null
+"color": null
+"productprice": "19.00"
+"productaddfee": "5.00"
+"subtotal": "24.00"
标签和数据应显示如下:
laboratory | product_type | product_name | serving_persons | desserttextmessage | dessertdecorchocolateID | dessertdecorflowerID | productprice | productaddfee | subtotal
Pâtissier | Gâteaux | Chocolat | 2-3 pers. | Inscription | Décoration chocolat et fruits souhaitée | Décoration petites fleurs souhaitée | 19.00 | 5.00 | 24.00
“部分”,“重量”,“分类_1”,“分类_2”,“分类3”,“分类4”,“颜色”列不属于“实验室” =“糕点师”。
如果“ laboratory” =“ Boulanger”:
+"laboratory": "Boulanger"
+"serving_persons": "2 pers. | 16 cm"
+"desserttextmessage": "Inscription Tarte"
+"dessertdecorchocolateID": "Décoration chocolat et fruits souhaitée"
+"dessertdecorflowerID": "Décoration petites fleurs souhaitée"
+"product_type": "Tarte"
+"product_name": "Tarte fraises"
+"portions": null
+"weight": null
+"assortment_1": null
+"assortment_2": null
+"assortment_3": null
+"assortment_4": null
+"color": null
+"productprice": "11.00"
+"productaddfee": "5.00"
+"subtotal": "16.00"
标签和数据应显示如下:
laboratory | product_type | product_name | serving_persons | desserttextmessage | dessertdecorchocolateID | dessertdecorflowerID | productprice | productaddfee | subtotal
Pâtissier | Gâteaux | Chocolat | 2-3 pers. | Inscription | Décoration chocolat et fruits souhaitée | Décoration petites fleurs souhaitée | 19.00 | 5.00 | 24.00
“部分”,“重量”,“分类_1”,“分类_2”,“分类_3”,“分类_4”,“颜色”列不属于“实验室” =“ Boulanger”。
产品可以超过3种,理论上是无限的。
这是我将数据提取到控制器中的方式:
# START SEND EMAIL TO X
$customer = $_REQUEST['userID'];
// dd($customer);
$customerdata = DB::table('cms_users')
->leftJoin('users_r3_details','cms_users.id', '=', 'users_r3_details.userID')
->select('cms_users.email','cms_users.name','cms_users.email','users_r3_details.title','users_r3_details.firstname','users_r3_details.lastname')
->where('cms_users.id', '=', $customer)
->first();
// dd($customerdata);
$orderdata = DB::table('orders_detail')
->leftJoin('dessert_servings','orders_detail.dessertservingID', '=', 'dessert_servings.id')
->leftJoin('product_types','orders_detail.producttype_ID', '=', 'product_types.producttypeID')
->leftJoin('product_names','orders_detail.productname', '=', 'product_names.productname_ID')
->leftJoin('party_loaf_portions','orders_detail.ID_portion', '=', 'party_loaf_portions.portion_ID')
->leftJoin('party_loaf_weights','orders_detail.partyloafweightID', '=', 'party_loaf_weights.id')
->leftJoin('party_loaf_sandwiches_1','orders_detail.partyloafsandwich1ID', '=', 'party_loaf_sandwiches_1.id')
->leftJoin('party_loaf_sandwiches_2','orders_detail.partyloafsandwich2ID', '=', 'party_loaf_sandwiches_2.id')
->leftJoin('party_loaf_sandwiches_3','orders_detail.partyloafsandwich3ID', '=', 'party_loaf_sandwiches_3.id')
->leftJoin('party_loaf_sandwiches_4','orders_detail.partyloafsandwich4ID', '=', 'party_loaf_sandwiches_4.id')
->leftJoin('party_loaf_ribbons','orders_detail.partyloafribbonID', '=', 'party_loaf_ribbons.id')
->select('orders_detail.laboratory','product_types.product_type','product_names.product_name','dessert_servings.serving_persons','orders_detail.desserttextmessage','orders_detail.dessertdecorchocolateID','orders_detail.dessertdecorflowerID','party_loaf_portions.portions','party_loaf_weights.weight','party_loaf_sandwiches_1.assortment as assortment_1','party_loaf_sandwiches_2.assortment as assortment_2','party_loaf_sandwiches_3.assortment as assortment_3','party_loaf_sandwiches_4.assortment as assortment_4','party_loaf_ribbons.color','orders_detail.productprice','orders_detail.productaddfee','orders_detail.subtotal')
->where('orders_detail.orderID', '=', $id)
->get();
// dd($orderdata);
$orderconfuserdataArray = (array) $customerdata;
$orderconforderdataArray = (array) $orderdata;
// dd($orderconfuserdataArray);
// dd($orderconforderdataArray);
$orderconfdatas = array_merge($orderconfuserdataArray, $orderconforderdataArray);
// dd($orderconfdatas);
$email = $customerdata->email;
$copyto ='';
// dd($email);
try {
// Example : Mail::to($request->user())->cc($moreUsers)->bcc($evenMoreUsers)->queue(new OrderShipped($order));
Mail::to($email)->send(new CustomerConfOrder($orderconfuserdataArray,$orderconforderdataArray));
echo 'Commande et confirmation de commande expédiées avec succès';
} catch (\Exception $e) {
echo 'Error - '.$e;
sleep(150);
}
# END SEND EMAIL TO X
感谢您的专业知识和建议,以解决此问题。
干杯,马克
================================================ ========================
更新:
在我的代码稍作更改后,我的数组现在看起来更加常规:
array:2 [▼
0 => {#1727 ▼
+"email": "client_1.mage@webamazingapps.com"
+"name": "Client Un"
+"title": "1"
+"firstname": "Un"
+"lastname": "Client"
}
1 => Collection {#1737 ▼
#items: array:1 [▼
0 => {#1733 ▼
+"laboratory": "Boulanger"
+"product_type": "Tarte"
+"product_name": "Tarte fraises"
+"serving_persons": "2 pers. | 16 cm"
+"desserttextmessage": "Inscription"
+"dessertdecorchocolateID": "Décoration chocolat et fruits souhaitée"
+"dessertdecorflowerID": "Décoration petites fleurs souhaitée"
+"portions": null
+"weight": null
+"assortment_1": null
+"assortment_2": null
+"assortment_3": null
+"assortment_4": null
+"color": null
+"productprice": "11.00"
+"productaddfee": "5.00"
+"subtotal": "16.00"
}
]
}
]
我再次尝试了foreach:
@foreach($Collection as $row)
{{$row->laboratory}}
{{$row->serving_persons}}
{{$row->desserttextmessage}}
@endforeach
或更简单地说:
{{$content['Collection']}}
获取我的内容,但再次没有任何数据打印到电子邮件中。
因为我被卡住了,所以在这里需要帮助。谢谢,马克
答案 0 :(得分:0)
您必须为该数组调用foreach
:
@foreach($content['\x00*\x00items'] as $data)
{{$data->laboratory}}
{{$data->serving_persons}}
{{$data->desserttextmessage}}
//and so on
@endforeach
答案 1 :(得分:0)
解决方案:
最后找到了解决方案,如何使结构化的foreach工作:
<table style="width:100%">
<tbody style="width: 100%">
<?php $three=0; ?>
@foreach($content['item'] as $contacts)
@if($three%3==0)
<tr style="width: 100%">
@endif
<td style="width: 33.3%;border: 1px solid #ded3d3;padding: 15px 15px;">
<?php $protype=''; ?>
@foreach($contacts as $check => $val)
<p style="margin: 5px 2px;">
<?php if($check=='product_type'&&$val=='Pain-surprise'){ $protype=$val; } ?>
@if($check=='productaddfee'&&$protype=='Pain-surprise')
@elseif($check=='dessertdecorchocolateID'&&$protype=='Pain-surprise')
@elseif($check=='dessertdecorflowerID'&&$protype=='Pain-surprise')
@else
@if($val!=''&&$val!=' ')
<span style="font-size: 18px;text-transform: capitalize;font-weight: 600;font-family: monospace;color:#b7252b">{{ $check }}</span> :
<span style="font-size: 15px;font-family: sans-serif;text-transform: capitalize;letter-spacing: 1px;font-weight: 600;">{{ $val }}</span>
@endif
@endif
</p>
@endforeach
</td>
@if($three%3==0&&$three!=0)
</tr>
@endif
<?php $three++; ?>
@endforeach
</tbody>