![](/img/trans.png)
[英]Laravel - How to pass a php variable to a javascript function from a blade file
[英]how to pass email variable from a class into blade in laravel
我有一堂课,负责处理电子邮件。
public function mail($emails, $message)
{
Mail::queue('emails.notification', ['message' => $message], function($m) use ($emails) {
$m->to($emails);
$m->subject('Notification....');
});
}
从$ this类中调用$ massage参数,
private function report(Notification $notification, $resCode)
{
if(empty($resCode)){
$resCode = "no response found";
}
$this->reporter->slack($notification->website_url . ':' . ' is down' . ' this is the status code!' . ' @- ' .$resCode,
$notification->slack_channel);
$this->reporter->mail($notification->email,$notification->website_url.' is down '. ' this is the status Code: '. $resCode);
}
现在我想在emails.notification.blade中显示消息,并且我尝试了这种方式
@extends('layout')
@section('header')
@stop
@section('content')
<h1>The Web site is down!</h1>
{{ $message }}
@stop
@section('footer')
@stop
[ErrorException]
htmlspecialchars() expects parameter 1 to be string, object given
这是我的例外。 有更好建议的人吗?
在控制器上:
$data = array('emailId' => $emailId, 'mailBody' => $mailBody);
$sendMailStatus = Mail::send('mail.emailForgotPassword', ['data' => $data], function ($message) use ($data) {
$message->from('xyz.com', 'abc');
$message->to($data['emailId'])->subject('Your Subject');
});
在刀片上:
{{ $data['mailBody'] }}
基于发送邮件 ,您可以将数组形式的变量值作为第二个参数传递。
Mail::send('templatepath', 'blade-variable', function($m) use($user){
$m->from('from@domain.com', 'From Label');
$m->to('to@domain.com', 'To Label')->subject('Subject');
});
在此, blade-variable是第二个参数。 您可以使用相同的值替换数组值。
此外,由于存在放置错误,因此htmlspecialchars()期望参数1为字符串,对象为给定 。 表示$message
变量不是字符串。 检查$message
值并传递类似以下的字符串: ['message' => 'This is the message..!']
希望这能消除您的疑问!
这个跟随链接
$info = array('firstname'=>'xyz','lastname'=>$lastname);
Mail::queue('emails.notification', ['message' => $info], function($m) use ($emails) {
$m->to($emails);
$m->subject('Notification....');
});
查看页面打印
{{ $message }}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.