Laravel-如何通过变量重置密码模板? [英] Laravel - How to pass variable to reset password template?
本文介绍了Laravel-如何通过变量重置密码模板?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经通过Laravel 5
实现了重置密码功能并收到了电子邮件.现在,如何将一些可变数据传递到我的电子邮件模板以显示有关用户的更多信息.
I have implemented reset password functionality with Laravel 5
and getting email. Now how to pass some variable data to my email template to display more information about user.
/**
* Send a reset link to the given user.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function postEmail(Request $request)
{
//echo Input::get('ID'); die;
$this->validate($request, ['ID' => 'required|email']);
$UserProduct = "Sample 1"; // I want to pass this variable to my password.blade.php
$response = Password::sendResetLink($request->only('ID'), function (Message $message) {
$message->subject($this->getEmailSubject());
});
switch ($response) {
case Password::RESET_LINK_SENT:
return redirect()->back()->with('status', trans($response));
case Password::INVALID_USER:
return redirect()->back()->withErrors(['ID' => trans($response)]);
}
}
我想将$UserProduct = "Sample 1";
打印到我的电子邮件模板,但是不知道如何传递到password.blade
页面.
I want to print $UserProduct = "Sample 1";
to my email template but don't know how to pass to the password.blade
page.
有什么主意吗?
谢谢.
推荐答案
sendResetLink
没有适当的方法来发送更多数据,如laravel中的常规电子邮件.
The sendResetLink
doesn't have a proper way to send more data like a regular email in laravel.
您可以使用一个视图作曲家来解决这个问题 :
You can kinda hack around this using a view composer, something like this:
$UserProduct = "Sample 1";
$infoArray = [1,2,3,4];
view()->composer('emails.auth.password', function($view) use ($UserProduct, $infoArray) {
$view->with([
'UserProduct' => $UserProduct,
'info' => $infoArray,
'more' => 'Even more info',
]);
});
$response = Password::sendResetLink($request->only('ID'), function (Message $message) {
$message->subject($this->getEmailSubject());
});
这篇关于Laravel-如何通过变量重置密码模板?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文