the issue was because, Localization will not work because the event is queued. Session and cookie will not work from the queue. So I passed locale as a parameter and now its working.
Sep 4, 2020
1
Level 18
LaravelLocalization currentLocale always returning from config file when triggering event.
I'm using https://github.com/mcamara/laravel-localization package for localization. URL seems to be working. I have some events that will send emails. I want to set the locale on the mail to send localized mails to the client. I tried setting the locale() method dynamically using LaravelLocalization::getCurrentLocale(). But its returning en that is from the config file.
event file
class NotifyClientBookingCreated implements ShouldQueue
{
/**
* Handle the event.
*
* @param ClientBookingCreated $event
* @return void
*/
public function handle(ClientBookingCreated $event)
{
Mail::to($event->booking->user->email)
->locale(LaravelLocalization::getCurrentLocale())
->send(new MailClientBookingCreated($event->booking));
}
}
I tried triggering the event using URL like
Route::group([
'prefix' => LaravelLocalization::setLocale(),
'middleware' => ['localeSessionRedirect', 'localeCookieRedirect', 'localizationRedirect', 'localeViewPath']
], function () {
Route::get('mailable', function () {
$booking = Booking::first();
event(new EventsClientBookingCreated($booking));
});
});
I'm using queued event
Level 18
1 like
Please or to participate in this conversation.