Answer the question
In order to leave comments, you need to log in
How to send letters through the queue so that the text of the letter is formed before queuing?
When sending emails via queue Laravel
Mail::to($email)->queue(new \App\Mail\NotifyReserveCreated($reserve, true));
the texts of the letters themselves are formed already in the process of processing the queue. Moreover, if a Laravel model is passed there, it is saved and restored in the queue. But sometimes this model is deleted even before the letter is sent, and as a result, an error occurs.
How is it possible (using standard Laravel tools) to send letters in such a way that the text would be formed even before queuing?
Answer the question
In order to leave comments, you need to log in
2 options:
1) make your own message class that will store the text of the message $this->content = (string)view('mails.message', $data) in the class field.
2) pass not the model object itself to the message class, but only an array with the necessary attributes $model->toArray()/getAttributes(), for example.
You are most likely using the SerializesModels mixin, which contains the logic to serialize (out of the box) the model. It, in fact, saves only the identifier and type of the model, and subsequently restores the entire model using this data.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question