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

Rayan_2018's avatar

Session not working in controller

i am using Global Session Helper in controller but i can't get values from it please see code below /** public $lang;

 * Where to redirect users after registration.
 *
 * @var string
 */
protected $redirectTo;

/**
 * Create a new controller instance.
 *
 * @return void
 */
public function __construct()
{
    $lang = session("language");
    $this->redirectTo = '/'.$lang.'/profile';
    dd($this->redirectTo);
    $this->middleware('guest');
}

the out put ://profile **/ please help me

0 likes
2 replies
tykus's avatar
tykus
Best Answer
Level 104

You cannot use the session in a Controller constructor - it is not available yet. I would suggest using a custom middleware to check the session and redirect the request if required

Rayan_2018's avatar

i just want to get value from session to assign it to $redirectTo how should i do that !!

Please or to participate in this conversation.