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
Your code looks correct. Try to restart your queue worker.
Queue workers are long-lived processes and store the booted application state in memory.
Try with below given code.