in my controller:
$order = Order::with('address','slot','products')->first(); Mail::to('abc@email.com') ->send(new OrderPlaced($order));
and in my OrderPlaced class:
class OrderPlaced extends Mailable { use Queueable, SerializesModels;
/**
* The order instance.
*
* @var Order
*/
public $order;
/**
* Create a new message instance.
*
* @return void
*/
public function __construct(Order $order)
{
$this->order = $order;
}
/**
* Build the message.
*
* @return $this
*/
public function build()
{
return $this->from('cs@xxx.com','My name')
->subject('Order #'.$this->order->id)
->view('emails.orders.placed');
}
} above code works awesome. however, when i put to queue by change the class OrderPlaced
class OrderPlaced extends Mailable implements ShouldQueue { use Queueable, SerializesModels;
/**
* The order instance.
*
* @var Order
*/
public $order;
/**
* Create a new message instance.
*
* @return void
*/
public function __construct(Order $order)
{
$this->order = $order;
}
/**
* Build the message.
*
* @return $this
*/
public function build()
{
return $this->from('cs@xxx.com','My name')
->subject('Order #'.$this->order->id)
->view('emails.orders.placed');
}
}
And got error from table failed_jobs: InvalidArgumentException: Invalid view. in /var/www/myapp/vendor/laravel/framework/src/Illuminate/Mail/Mailer.php:379
I've just resolved the similar issue. Without using a queue everything worked all right, but when I added ShouldQueue to my class responsible for the sending of email I received the same exception. In my case there was a call to helper request() in function build(). Instead of this, I should have used dependency injection to pass the necessary data to this class, which is suggested by documentation. Maybe, this will help
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community