Using PasswordBroker
and based on Illuminate/Auth/Passwords/PasswordBroker.php
, $emailView
is a protected variable, so you cannot change the value after instantiating the class.
However, you have several solutions:
You can create your own class that extends PasswordBroker and will use it.
class MyPasswordBroker extends PasswordBroker { public function setEmailView($view) { $this->emailView = $view; } } // (...) public function __construct(Guard $auth, MyPasswordBroker $passwords) { $this->auth = $auth; $this->passwords = $passwords; } public function sendReset(PasswordResetRequest $request) { if ($someConditionHere) { $this->passwords->setEmailView('emails.password_alternative'); } $response = $this->passwords->sendResetLink($request->only('email'), function($m) { $m->subject($this->getEmailSubject()); }); }
You can create a PasswordBroker in your method without using Injection Dependency.
public function sendReset(PasswordResetRequest $request) { $emailView = 'emails.password'; if ($someConditionHere) { $emailView = 'emails.password_alternative'; } $passwords = new PasswordBroker( App::make('TokenRepositoryInterface'), App::make('UserProvider'), App::make('MailerContract'), $emailView ); $response = $passwords->sendResetLink($request->only('email'), function($m) { $m->subject($this->getEmailSubject()); }); }
This is an ugly solution, and if you have automated tests, it will be a pain to work with.
Disclaimer: I have not tested this code.
source share