Level 104
$this->session()?
Besides, there would be no session if the job was queued
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hey, I am trying to send a Mail, based on the sessions language value.
SendMailJob
public function handle()
{
$email = new HelloMail($this->user);
if ($this->session()->has('lang') == 'en') {
$language = 'en';
} elseif ($this->session()->has('lang') == 'de') {
$language = 'de';
} else {
$language = 'en';
}
Mail::to($this->user->email)->locale($language)->send($email);
}
I am running into Call to undefined method HelloMail::session()
Any suggestions how to get the session()->has('lang') attribute?
Thank you
You should pass language while queueing job.
dispatch(new SendMailJob($request->session()->get('lang', 'en')));
public function __construct($lang)
{
$this->lang = $lang;
}
public function handle()
{
Mail::to($this->user->email)->locale($this->lang)->send(new HelloMail($this->user));
}
Please or to participate in this conversation.