我瞄准的最终结果(如果可能的话):
要遍历所有$users
及其$properties
,请抓住属性地址,然后通过$complaints
(投诉属于属性)进行迭代,并为每个属性创建<table>
它的投诉,财产可能没有投诉,所以也需要检查。
我确实尝试过这段代码并设法将所有$数据放入一个数组中,但首先我不能在电子邮件视图中迭代它,其次,如果我有1000个属性,每个属性将有30个投诉..你明白了......不好......
$users = User::all()->toArray();
foreach ($users as $user)
{
$report = [];
$properties = Property::where('user_id', $user['id'])->get()->toArray();
array_set($report, 'user', $user);
foreach ($properties as $property)
{
array_set($report, 'properties', $property);
$complaints = Complaint::where('property_id', $property['id'])->where('status', 'ACT')->get()->toArray();
foreach ($complaints as $complaint)
{
array_set($report, 'complaints', $complaint);
}
}
Mail::queue('emails.reports.weekly', $report, function($message) {
$message->to($report['user']['email'])->subject('Weekly Report');
});
}