Support the ongoing development of Laravel.io →
posted 6 years ago

user.php

public function sendPasswordResetNotification($token)
    {
        $this->notify(new sendResetPassword($token));
    } 

My notification class

namespace App\Notifications;

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

class sendResetPassword extends Notification
{
    use Queueable;

    public $token;

    /**
     * Create a new message 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)->markdown('emails.reset.send');
    }

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

In my notification class i get the token on function toMail. How can i pass it to markdown view? Always says undefined variable. O tried everything. This is probably something simple...

Last updated 3 years ago.
0

Solved.

public function toMail($notifiable)
    {
        $token = $this->token;
        return (new MailMessage)->markdown('emails.reset.send', ['token' => $token]);
    }

I knew it was something simple...

0

Sign in to participate in this thread!

Eventy

Your banner here too?

Ricardo Faria faria55 Joined 12 Mar 2019

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.