Unable to get session store value laravel 5.4

enter image description hereI'm storing my user id upon click of different users list using this method to store user_id in session

Session::put('user_id', $request->id);

and getting this user_id in another method of controller by using

$id = Session::get('user_id');

but each time I am getting the same id instead of a different upon clicking of different list users. What am I doing wrong? Do I need to destroy the session? The session value is not overriding.

You can use session global helper to store data in sessions

session(['key' => 'value']);

retrieve data using global helper

$value = session('key');

or you can use request instance

$request->session()->put('key', 'value');

retrieve data using request instance

$value = $request->session()->get('key', 'default');

more details link

enter image description hereI'm storing my user id upon click of different users list using this method to store user_id in session. Session::put('user_id'  When you retrieve a value from the session, you may also pass a default value as the second argument to the get method. This default value will be returned if the specified key does not exist in the session.

Did you check if you store in the session the good $request->id?

Master, 7.x, 6.x · 5.8 · 5.7 · 5.6 · 5.5 · 5.4 · 5.3 · 5.2 · 5.1 · 5.0 · 4.2 If you pass a Closure as the default value to the get method and the You may also use the global session PHP function to retrieve and store data in the session. thrown if the request is unable to obtain a session lock within the given number of seconds​. nandanvrs changed the title [Laravel 5.2]Session store not set on request [5.2]Session store not set on request Dec 25, 2015 GrahamCampbell closed this Dec 25, 2015 This comment has been minimized.

If you don't need the session user_id once after you use it, you can use following.

Retrieving And Deleting An Item.

$id = $request->session()->pull('user_id', 'default')]);

The pull method will retrieve and delete an item from the session Read more : https://laravel.com/docs/5.1/session

The session configuration file is stored at config/session.php . If you pass a Closure as the default value to the get method, the Closure will be executed and its  The open method would typically be used in file based session store systems. Since Laravel ships with a file session driver, you will almost never need to put anything in this method. You can leave it as an empty stub.

Add below code on top of your class declaration

use Session;

and in your function add below code to print all the session values

$arrMixSessionData   = Session::all();
echo '<pre>';
echo '<pre/>';

To retrieve the selected session variable, you need to add request variable in the function declaration and use as below

function test(Request $request){
    $value = $request->session()->get('key', 'default');

Hopes it will help you.

Hi, so we recently upgraded Laravel from 5.1 to 5.4, I wasn't involved in the upon login/other tasks, and I figured out that our session variables aren't getting set. are you getting files created in storage/framework/sessions? Hi Everyone, I have upped my session timeout value in config\session.php but my user gets logged out still and it does not seem like the timeout value I specified in config\session.php is applied at all.

hello every one i am new to laravel. i am trying to store db values in session and want to display whenever its needed. but i cant display all values echo $val=​Session::get('first_name'); else echo 'No data in the session';. } public function Ref: https://laravel.com/docs/5.4/session#using-the-session. @knabity I 'am using Laravel 5.1. i am facing same issue which you have mentioned above "Session store not set on request". I am new to PHPunit, can you give me the workaround so i can fix that issue. Thankx.

Hi, I am badly struggling with this problem and still unable to find solution. It is simplest thing i am trying to do, i am just trying to store a variable  By default, this value is set to the storage/app directory. Therefore, the following method would store a file in storage/app/file.txt: Storage::disk('local')->put('file.txt', 'Contents'); Permissions. The public visibility translates to 0755 for directories and 0644 for files. You can modify the permissions mappings in your filesystems

Can't have access to auth user on Controller on L5.3 #14699 https://laravel-​news.com/controller-construct-session-changes-in-laravel-5-3  Laravel allows you to keep input from one request during the next request. This feature is particularly useful for re-populating forms after detecting validation errors. However, if you are using Laravel's included validation features, it is unlikely you will need to manually use these methods, as some of Laravel's built-in validation

  • If I write above two lines session put and session get write next to each other in same method then I'm getting correct id and session value,but if I get in different method I'm not getting.why?
  • Actually,I'm setting session id in controller method calling from ajax.and the ajax method call upon onclick of user list.
  • Yes, in the same method $request->id storing in session.
  • My session value is stored in session and I'm getting default answer by using your above line.which mean im not getting session value in different method but getting in same method of controller.
  • If you can, share the codes in controller or take a screenshot
  • Thanks for your reply, Array ( [_previous] => Array ( [url] => localhost/marketplace/public/update-service ) [_flash] => Array ( [old] => Array ( ) [new] => Array ( ) ) [_token] => aUhfVMGSeefkELlfAv15uYMCnymUteDp5PENQ8p6 [login_web_59ba36addc2b2f9401580f014c7f58ea4e30989d] => 1 [user_id] => 7 ) I called this method where I store session,my id is setting as 7.
  • but If I call the same method where i want to retreive session value,this method return empty array.why?
  • why don't you use like $arrMixSessionData['user_id'], or send me your function code, I'll check on it.
  • or try like this Session::get('user_id');
  • public function consumerProfile(Request $request){ $id = $request->session()->pull('user_id', 'default'); $modal = modal::where('user_id' , $id)->first(); $booking = Booking::where('user_id' , $id)->first(); $user = User::where('id' , $id)->first(); return view('consumer.consumerProfile' , compact('modal','booking', 'user')); } public function customerDetail(Request $request){ $data = array(); $request->session()->put('user_id' , $request->id); echo json_encode($data); exit(); }