[英]Laravel Mail Undefined Variable
I am trying to send email using Laravel Mail & getting Undefined variable: data in view. 我正在尝试使用Laravel Mail发送电子邮件并获取未定义变量:数据在视图中。 Here is my controller code.
这是我的控制器代码。
$insured = Claim::where('id', '=', $claim_id)->first()->toArray();
$workshop = Workshop::where('id', '=', $insured['workshop_id'])->first()->toArray();
$data = Document::whereRaw('claim_id = ' . $claim_id . ' AND (documents.status = 10 OR documents.status = 12)')
->join('docs','documents.doc_id', '=', 'docs.id')
->join('claims','documents.claim_id', '=', 'claims.id')
->get(array('docs.email_text', 'claim_of', 'vehicle_no'))->toArray();
Mail::send('emails.workshop', $data, function($message)
{
$message->to('someone@somedomain.com')->subject('Testing');
});
View 视图
{{ $data[0]['claim_of'] }}
<br />
{{ $data[0]['vehicle_no'] }}
<br />
<?php $i = 1 ; ?>
@foreach($data as $key => $claim)
<p> {{ $i }}. {{ $claim->email_text }}</p>
<?php $i++ ; ?>
@endforeach
When I replace Laravel Mail code with 当我将Laravel Mail代码替换为
return View::make('emails.workshop')->with('data', $data);
everything works perfectly. 一切正常。
Parameters have to be passed in as key value array 参数必须作为键值数组传递
Mail::send('emails.workshop', array('data' => $data), function($message)
{
$message->to('someone@somedomain.com')->subject('Testing');
});
There's a nice PHP function called compact
that does this automatically, based on the variable name. 有一个很好的PHP函数,称为
compact
,可以根据变量名自动执行此操作。
So compact('data')
returns array('data' => $data)
(if $data
is defined) 所以
compact('data')
返回array('data' => $data)
(如果$data
被定义)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.