Question: Laravel 5.3 passing data to password reset template failing


Laravel 5.3 passing data to password reset template failing

Answers 3
Added at 2016-12-26 13:12

I am trying to pass a pageTitle variable to the password reset template (/resources/views/auth/passwords/reset.blade.php) in Laravel 5.3 in the following way:

return view('auth.passwords.reset')
    ->with('pageTitle', 'Change title')
    ->with(['token' => $token, 'email' => $request->email]);

this goes in the showResetForm method inside ResetsPasswords trait - and it doesn't work. Google doesn't come up with any helpful results. I've tried removing the line:

    ->with(['token' => $token, 'email' => $request->email]);

but it still doesn't work. I've also tried

$pageTitle = 'Change me';
return view('auth.passwords.reset', compact('pageTitle'));

but it doesn't work. Also, I've realized that the ResetsPassword trait is found in the vendor folder so it's a bad idea to change the code there, how do you suggest I do this instead? Can I overwrite the showResetForm method somewhere? - I found that for the registration trait I can put the showRegistrationForm in the RegistrationController and pass whatever variables I want to the view there; however that doesn't work for the ResetPasswordController


Here is the whole method from the ResetsPasswords trait, as requested:

 * Display the password reset view for the given token.
 * If no token is present, display the link request form.
 * @param  \Illuminate\Http\Request  $request
 * @param  string|null  $token
 * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
public function showResetForm(Request $request, $token = null)
    return view('auth.passwords.reset')->with(['token' => $token, 'email' => $request->email]);
nr: #1 dodano: 2016-12-26 13:12
return view('auth.passwords.reset')
    ->with(['pageTitle' => 'Change Title','token' => $token, 'email' => $request->email]);

have you tried it like this?


$pageTitle = 'Change Title';
$token = 'token';
$email = 'email';
return view('auth.passwords.reset', compact('pageTitle','token','email'));
nr: #2 dodano: 2016-12-26 13:12

Try using compact

return view('auth.passwords.reset', compact('token', 'email', etc..));
nr: #3 dodano: 2016-12-26 18:12

The problem was I was editing the wrong trait, I need to edit the SendsPasswordResetEmails trait and not the ResetsPassword.

Source Show
◀ Wstecz