skip to Main Content

Hello in my laravel application i have a moment when the user is notified on mail when tha order is complete.

`
In my controller i have:

Mail::to('test@mail')->send(new OrderSuccess($id));

// $id is a string

in mail.php

<?php

namespace AppMail;

use IlluminateBusQueueable;
use IlluminateContractsQueueShouldQueue;
use IlluminateMailMailable;
use IlluminateQueueSerializesModels;

class OrderSuccess extends Mailable implements ShouldQueue
{
    use Queueable, SerializesModels;

    public $order_id;

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

    /**
     * Build the message.
     *
     * @return $this
     */
    public function build()
    {
        return $this->view('mails.ordermail')
                    ->with([
                        'order_id' => $this->order_id
                    ]);
    }
}

In mail blade template:

Test order n. {{ $order_id }}

But i’m getting a failed job that shows this error

ErrorException: Undefined variable $order_id in C:Users…

What am i doing wrong?

`

2

Answers


  1. Your code looks correct. Try to restart your queue worker.

    Queue workers are long-lived processes and store the booted application state in memory.

    Login or Signup to reply.
  2. Try with below given code.

    return $this->view('mails.ordermail',['order_id' => $this->order_id]);
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search