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

dhiru027's avatar

How to use session in custom facade in Laravel 5.5

I am new to Laravel and working on version 5.5. For my knowledge, I have created custom facade and now I am trying to set some session values into this facade as well as try to get the value of set session.

But Laravel is not able to set session in this custom facade. If I do the same thing in controller then it is working fine.

Below are my possible way that I have tried:

public function setUserSession() {  
   //Ist way
   session()->put('user', 'some values');
   var_dump(session()->has('user')); // this is returning me false  

   //2nd way  
   request()->session()->put('user', 'some values');  
   var_dump(request()->session()->has('user')); // this is returning me false 

   Session::set('user', 'some values');  //this is giving me error
   /* for above line I have include below namespace:  
      1.Illuminate\Support\Facades\Session  
   */  
   var_dump(Session::get('user')); // this is returning me false 
}  

Even I have tried the solutions of below link:

https://stackoverflow.com/questions/43048945/how-to-use-session-in-custom-class-laravel-5

But nothing change. Please anyone share your solution for this issue?

Thanks in Advance.

0 likes
2 replies
sherwinmdev's avatar

@dhiru027 by default, the session driver is set to file. it's possible that permissions may not be allowing to write to this file? just a guess.

dhiru027's avatar

Thanks for your reply. I have checked and session driver is using file. But the same process I am following in Laravel 5.4 then session is working fine. I don't know that this issue is cause of version or something else.

Please help me

Please or to participate in this conversation.