Here is a solution that worked for me. In my example, I process an order in a queue using the selected Job class.
When you submit the task to the queue, skip the locale, you want your email address to be. For instance:
ProcessBooking::dispatch($booking, \App::getLocale());
Then in your job class ( ProcessBooking in my example) save the locale in the property:
protected $booking; protected $locale; public function __construct(Booking $booking, $locale) { $this->booking = $booking; $this->locale = $locale; }
And in your handle method, temporarily switch the locales:
public function handle() { // store the locale the queue is currently running in $previousLocale = \App::getLocale(); // change the locale to the one you need for job to run in \App::setLocale($this->locale); // Do the stuff you need, eg send an email Mail::to($this->booking->customer->email)->send(new NewBooking($this->booking)); // go back to the original locale \App::setLocale($previousLocale); }
Why do we need this?
The email queue receives the default locale because the queue workers are separate Laravel applications. If you ever had a problem when you cleared your cache, but in the queue βthingsβ (for example, emails) still showed the old content, because of this. Here's an explanation from the Laravel docs :
Remember that work queues are long-lived processes and store the state of a loaded application in memory. As a result, they will not notice changes in the code base after they are launched. Therefore, be sure to restart your queue employees during the deployment process.
Amade source share