У меня проблема с почтой при использовании queue
. Если я использую Почту с send()
, все работает нормально.
Контроллер:
Mail::to($order_data->client_email)
->cc([
['email' => $order_data->seller->email],
['email' => auth()->user()->email]
])
->queue(new SendOrderConfirmation($order_data));
Почтовый ящик:
class SendOrderConfirmation extends Mailable
{
use Queueable, SerializesModels;
/**
* Defines a public variable $order_data that we will be using to pass in parameters from our controller.
*/
public $order_data;
/**
* Create a new message instance.
*/
public function __construct($data)
{
// set email data
$this->order_data = $data;
// Set Reply to address
// Basically, the name and email from who's sending this email
$this->replyto(auth()->user()->email, auth()->user()->name);
// Set from
$this->from(auth()->user()->email, auth()->user()->name);
// set email subject
$this->subject('Laminar - Confirmação da Encomenda N.º '.$this->order_data->order_nr);
}
/**
* Build the message.
*
* @return $this
*/
public function build()
{
return $this->view('send_emails.Lamimail.SendOrderConfirmation');
}
}
Если я инициирую электронное письмо с очередью (), Я получаю сообщение об ошибке в заданиях телескопа:
Trying to get property 'name' of non-object
(View: path\resources\views\send_emails\Lamimail\SendOrderConfirmation.blade.php)
Но в представлении почты имя простое auth()->user()->name
.
Кто-нибудь знает, что я отсутствует в очереди?
С уважением
РЕШЕНИЕ , на основе отзывов @Ersoy. Обратите внимание на public $sender_name;
Отправляемое по почте:
{
use Queueable, SerializesModels;
/**
* Defines a public variable $order_data that we will be using to pass in parameters from our controller.
*/
public $order_data;
/**
* Will be used to save the sender name
*/
public $sender_name;
/**
* Create a new message instance.
*/
public function __construct($data)
{
// set email data
$this->order_data = $data;
// Set sender name to be used on mail view
$this->sender_name = auth()->user()->name;
// Set Reply to address
// Basically, the name and email from who's sending this email
$this->replyto(auth()->user()->email, auth()->user()->name);
// Set From
$this->from(auth()->user()->email, auth()->user()->name);
// set email subject
$this->subject('subject...');
}
/**
* Build the message.
*
* @return $this
*/
public function build()
{
return $this->view('view...');
}
}