Laravel - 将数据传递到电子邮件视图
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/32500766/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Laravel - Passing data to email view
提问by Stephan-v
I can not access the confirmation_code variable in my email.verify view by using this variable in my view:
我无法通过在我的视图中使用这个变量来访问我的 email.verify 视图中的 Confirmation_code 变量:
$user->confirmation_code
Shouldn't this be accessible when I assigned the array items like this? What am I overlooking?
当我分配这样的数组项时,这不应该可以访问吗?我在看什么?
$user = User::create([
'name' => $data['name'],
'email' => $data['email'],
'password' => bcrypt($data['password']),
'confirmation_code' => str_random(30)
]);
Mail::send('emails.verify', ['user' => $user], function ($m) use ($user) {
$m->to($user->email, $user->name)->subject('Email verificatie');
});
All the other variables like, name, email, password are accessible and I am giving the mail send method my user object.
所有其他变量,如姓名、电子邮件、密码都是可访问的,我将邮件发送方法提供给我的用户对象。
采纳答案by Mihkel Allorg
Did you add 'confirmation_code'
to the array $fillable
in the User.php file?
您是否添加'confirmation_code'
到$fillable
User.php 文件中的数组?
回答by Sid
Seems like your are not passing your confirmation_code
to the email template. Just save confirmation code
to some variable
似乎您没有将您confirmation_code
的传递给电子邮件模板。只需保存confirmation code
到某个变量
Mail::send('emails.verify', ['user' => $user, 'confirmation_code' => $yourConfirmationCodevariable ], function($m){
$$m->to($user->email)->subject('Transaction Details');
});
And in your verify.blade
而在你 verify.blade
just do {{ $confirmation_code }}
做就是了 {{ $confirmation_code }}
回答by Luca C.
You can pass variables in Mailable views, by doing this:
您可以通过执行以下操作在 Mailable 视图中传递变量:
...
public function build()
{
return $this->view('emails.viewname')->with(['explicit_variable' => $some_value]);
}
...