Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

ajithlal's avatar

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

0 likes
1 reply
ajithlal's avatar
ajithlal
OP
Best Answer
Level 18

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.

1 like

Please or to participate in this conversation.