'Attempt to read property \"view\" on null when sending password reset email

I am trying to build password reset functionality but with a custom email template. So instead of returning the MailMessage from the notification I can sending my own custom mail.

Sending the email is working but the problem is in postman I get a 500 with this error

 "message": "Attempt to read property \"view\" on null",
    "exception": "ErrorException",
    "file": "/home/vagrant/api/vendor/laravel/framework/src/Illuminate/Notifications/Channels/MailChannel.php",
    "line": 92

Here is my code

Password reset method in my controller

public function sendResetPasswordLink(SendResetPasswordLinkRequest $request)
{
    $status = Password::sendResetLink($request->only('email'));

    if($status == Password::RESET_LINK_SENT) {
        return "work";
    }
}

sendPasswordResetNotification method in User model

public function sendPasswordResetNotification($token) 
{
    \Illuminate\Support\Facades\Log::info('sendPasswordResetNotification ran');
    $url = $this->clientBaseUrl . '/reset-password/' . $token;

    $this->notify(new ResetPasswordNotification(request('email'), $url));
}

toMail method in ResetPasswordNotification class

 public function toMail($notifiable)
    {
        return Mail::to($this->email)->send(new ResetPasswordMail($this->url));
    }

Then is the ResetPasswordMail class I simply return the view in the build method

public function build()
{
    return $this->markdown('emails.reset-password')->subject('Welcome to Walor!');
}

So I am getting an email with this template but in postman I am getting a 500 with the error on the top



Solution 1:[1]

write toMail method like this :

 public function toMail($notifiable)
{
    return (new ResetPasswordMail($this->url))
                ->to($notifiable->email);
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 alireza mac