Laravel - How to pass variable to reset password template?

删除回忆录丶 提交于 2019-12-20 03:39:48

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!