Skip to content

Cannot access custom data #112

Open
Open
@hktang

Description

@hktang

I am trying to pass custom data App\Review and App\Reviewer into the notification message.

However, it seems the email message cannot access those values, resulting in an error. Both $review and $reviewer are null.

This is how the notification is set up. Where did I get it wrong?

<?php

namespace App\Notifications;

use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;

class ReviewDueSoon extends Notification
{
    use Queueable;

    public $review;
    public $reviewer;

    /**
     * Create a new notification instance.
     */
    public function __construct($review, $reviewer)
    {
        $this->review = $review;
        $this->reviewer = $reviewer;
        ...
    }

    public function via($notifiable)
    {
        return ['mail'];
    }

    public function toMail($notifiable)
    {
        $mailMessage = new MailMessage();
        ...

        // $this->review is null
        // $this->reviewer is null

        return $mailMessage;
    }

  }

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinghelp wantedExtra attention is needed

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions