【发布时间】:2019-08-21 15:36:02
【问题描述】:
我正在尝试将包含多个用户数据的多维数组传递给我的视图,以便我可以将其作为列表发送到电子邮件中。但是当我在邮件视图中调用我的数组时,我总是收到错误“未定义的变量”。
我已经尝试使用 foreach 和 for 调用我的数组,但都没有工作,还尝试在我的视图上直接调用我的数组中的键,但我也得到了“未定义的变量”。
功能:
public function handle()
{
$tubes = DB::table('tubes')->where('status','received')->select('TubeID', 'TestArrivalDate')->get();
$tubes = json_decode($tubes, true);
if(!is_null($tubes)){
$date = date('Y-m-d H:i:s');
foreach ($tubes as $tube) {
$diff = Carbon\Carbon::parse($tube['TestArrivalDate'])->diffInDays();
$Email = DB::table('tubes')->join('profile', 'profile.ProfileID', 'tubes.ProfileID')->where('TubeID', $tube['TubeID'])->select('ProfileEmail', 'ProfileName')->get();
$Email = array_flatten(json_decode($Email, true));
if ($diff > 14) {
$TubesDelay[]=array('TubeID' => $tube['TubeID'],'TestArrivalDate' => $tube['TestArrivalDate'], 'DaysWaiting' => $diff, 'ProfileEmail' => $Email[0], 'ProfileName' => $Email[1]);
}
}
// dd($TubesDelay);
Mail::send('mail.DelayedSamplesMail', $TubesDelay, function($message)
{
$message->from('kundenservice@test', 'kundenservice@test');
$message->to(['m.lara@test'])->subject('Sample Delay');
});
}
}
查看:
<span style="font-size: 11pt; font-family: Poppins Light">
<br />
Following Samples are received and have delay:
@foreach ($TubesDelay as $sample)
<td>{{$sample}}</td>
@endforeach
<br />
<br />
<br />
</span>
我想要的是将数组中所有用户的数据作为列表放在电子邮件中。所以我的数组是这样的
array:5 [
0 => array:5 [
"TubeID" => 1005029
"TestArrivalDate" => "2019-06-21"
"DaysWaiting" => 61
"ProfileEmail" => "mat@test.world"
"ProfileName" => "MLB"
]
1 => array:5 [
"TubeID" => 1005034
"TestArrivalDate" => "2019-07-08"
"DaysWaiting" => 44
"ProfileEmail" => "mat@test.com"
"ProfileName" => "MLB2"
]
我想列出数组中的所有数据
TubeID 1005029
TestArrivalDate 2019-06-21
DaysWaiting 61
ProfileEmail mat@test.world
ProfileName MLB
TubeID 1005034
TestArrivalDate2019-07-08
DaysWaiting 44
ProfileEmail mat@test.com
ProfileName MLB2
【问题讨论】:
标签: laravel