Charrua
136
1
Laravel

Getting error outeNotificationFor() on batch email notifications

Posted 6 months ago by Charrua

Hello, I'm trying to send email to members on my app and I get the following error:

production.ERROR: Call to undefined method Illuminate\Database\Query\Builder::routeNotificationFor() {"exception":"[object] (BadMethodCallException(code: 0): Call to undefined method Illuminate\Database\Query\Builder::routeNotificationFor() at /var/www/vhosts/.../laravel/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php:2483)

I have the members model with the Notifiable trait and the weird issue is that on my local machine the emails are delivered... The problem is on production... Any ideas?

The notifications are fired with:

Notification::send($members_to_notify, new CommMessage($communication));

And the CommMessageclass is:


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

use App\Mail\Communications\Message as Mailable;

class CommMessage extends Notification implements ShouldQueue
{
    use Queueable;

    private $communication;

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

    /**
     * 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 Mailable
     */
    public function toMail($notifiable)
    {
        return (new Mailable($this->communication))->to($notifiable->email);
    }
    
}

The mailable Message class is:

namespace App\Mail\Communications;

use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Queue\ShouldQueue;

class Message extends Mailable
{
    use Queueable, SerializesModels;

    /**
     * The appointment instance.
     *
     * @var Appointment
     */
    public $communication;
    
    /**
     * Create a new message instance.
     *
     * @return void
     */
    public function __construct($communication)
    {
        $this->communication = $communication;

    }

    /**
     * Build the message.
     *
     * @return $this
     */
    public function build()
    {
        $this->replyTo($this->communication->school->email)->markdown('emails.communications.message');

        $this->subject($this->communication->title);

        $this->withSwiftMessage(function ($message) {
            $message->getHeaders()
                    ->addTextHeader('X-Mailgun-Variables', json_encode([
                        'model_id' => $this->communication->id,
                        'model' => get_class($this->communication),
                        'email_type' => 11 //Communication message (EmailLogType)
                    ]));
        });

    }

}

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.