问题
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)]);
}
}
I want to print $UserProduct = "Sample 1";
to my email template but don't know how to pass to the password.blade
page.
Any idea?
Thanks.
回答1:
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());
});
来源:https://stackoverflow.com/questions/34529750/laravel-how-to-pass-variable-to-reset-password-template