0

I am to append the users email address in the URL when doing password reset, so the reset url would look like this http://blog.dev/password/reset/4cfbb048346474aab7080c88f16c34b9ea377b9ea35804387216fce303a38855?email=test%40gmail.com

However I get the error FatalErrorException in CustomResetPassword.php line 54: Call to undefined method App\Notifications\CustomResetPassword::getEmailForPasswordReset()

I am sending the reset email through a custom notification class the code is as follows

namespace App\Notifications;


use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;


class CustomResetPassword extends Notification
{
use Queueable;


public $token;



/**
 * Create a new notification instance.
 *
 * @return void
 */
public function __construct($token)
{
    $this->token = $token;

}

/**
 * Get the notification's delivery channels.
 *
 * @param  mixed  $notifiable
 * @return array
 */
public function via($notifiable)
{
    return ['mail'];
}

/**
 * Get the mail representation of the notification.
 *
 * @param  mixed  $notifiable
 * @return \Illuminate\Notifications\Messages\MailMessage
 */
public function toMail($notifiable)
{
     return (new MailMessage)
        ->subject('Reset Password')
        ->line('You are receiving this email because we received a password reset request for your account.')
        ->action('Reset Password', url('password/reset', $this->token).'?email='.urlencode($this->getEmailForPasswordReset()))
        ->line('If you did not request a password reset, no further action is required.');
}

/**
 * Get the array representation of the notification.
 *
 * @param  mixed  $notifiable
 * @return array
 */
public function toArray($notifiable)
{
    return [
        //
    ];
}
}

Am I missing something here?

Caleb Oki
  • 667
  • 2
  • 11
  • 29

1 Answers1

0

$this refer to your actual class, you're trying to use getEmailForPasswordReset method of CustomResetPassword but this method doesn't exist.

You can pass the email to the notification as you did for the token.

jeanj
  • 2,106
  • 13
  • 22
  • I did what you suggested, I passed the email into the constructor public `function __construct($token, $email) { $this->token = $token; $this->$email = $email; }` then I called the method `$this->email->getEmailForPasswordReset()` Now I get the error `ErrorException in CustomResetPassword.php line 26: Missing argument 2 for App\Notifications\CustomResetPassword::__construct(), called in C:\xampp\htdocs\blog\app\User.php on line 34 and defined` – Caleb Oki Dec 14 '16 at 10:17
  • If this solved your issue, don't forget to mark the answer as accepted. It will be nice for anybody else asking the same. – jeanj Dec 14 '16 at 10:19
  • I wont forget to mark a solution. However the issue is not yet solved – Caleb Oki Dec 14 '16 at 10:25
  • You edited with the code after my comment. You forgot to pass the email when you call your notification – jeanj Dec 14 '16 at 10:27
  • Please could you explain how I could do that? Do you mean setting the email variable like `public $email` – Caleb Oki Dec 14 '16 at 10:34
  • Yes you have to do the same as `$token`, create the property and assign it in the constructor. Can you show me the code that fire this notification? – jeanj Dec 14 '16 at 10:36
  • 1
    Thanks, I've solved it using the ideas here http://stackoverflow.com/questions/40703804/laravel-5-3-how-to-show-username-in-notifications-email?rq=1 – Caleb Oki Dec 14 '16 at 10:46