Reputation: 956
ok, so I'm trying to store a session at Login when someone Logs in. I'm storing the session, saving it, but at the next page, I can't retrieve that session. It's a null output. The storage folder is set to 775, so I don't see why it wouldn't be writing. Auth session get's wrote btw, it's just the Session::put() keys that aren't being stored. Below is the code:
LoginController.php
if(Auth::attempt(['username' => $this->user, 'password' => $inp->password, 'Login' => $this->acct]))
{
# [2]: If TRUE, Create sessions, redirect
$authArr = SubUsers::join('sub_services as ss', 'sub_users.userid', '=', 'ss.userid')->where('sub_users.username', $this->user)->first()->toArray();
// Create The Sessions
Session::put('Username', $this->user); # constant | User that's currently logged in
Session::put('Account', $this->acct); # changing | Account Data being passed to view
Session::save();
Session::push('Auth', $authArr);
// Redirect
if(Session::has('lasturl')){
$lasturl = Session::get('lasturl');
return Redirect::to($lasturl);
}
else { return Redirect::to($this->startScreen); }
}
BaseAppController.php
public function __construct()
{
dd(Session::has('Username')); # [ This Returns Null ]
}
UPDATE: Below is the session getting stored in the storage/framework/sessions folder. It's being stored correct:
a:8:{s:6:"_token";s:40:"dEf3bJ4vz9fjiUuVnjD5EKNIKgJ38UzgZ0q4aE7K";s:9:"_previous";a:1:{s:3:"url";s:43:"http://localhost:8888/alpha/public/settings";}s:5:"flash";a:2:{s:3:"old";a:0:{}s:3:"new";a:0:{}}s:38:"login_82e5d2c56bdd0811318f0cf078b78bfc";i:78;s:8:"Username";s:4:"demo";s:7:"Account";s:4:"demo";s:4:"Auth";a:1:{i:0;a:20:{s:6:"userid";i:78;s:7:"groupid";N;s:5:"Login";s:4:"demo";s:8:"username";s:4:"demo";s:8:"password";s:60:"$2y$10$9Q1/zGeRrrDwl2rfjmkIWuWv3V/LpgFVYR/68PjANCsIkKmIVRVAu";s:4:"name";s:11:"John Babtis";s:5:"email";s:16:"[email protected]";s:14:"remember_token";s:60:"2dqaWk56uJ1ldTdHhLcGg5U47JGxAD7EKdqwlr5qpPMGat9BKpMTf8tDtUlL";s:13:"userserviceid";i:81;s:9:"SuperUser";i:1;s:13:"MasterAccount";i:1;s:14:"canCreateUsers";i:1;s:12:"canEditUsers";i:1;s:2:"hm";i:1;s:6:"demand";i:1;s:9:"pophealth";i:1;s:12:"appointments";i:1;s:7:"reports";i:1;s:8:"settings";i:1;s:12:"canEditChild";i:1;}}s:9:"_sf2_meta";a:3:{s:1:"u";i:1437755751;s:1:"c";i:1437755740;s:1:"l";s:1:"0";}}
Upvotes: 2
Views: 4496
Reputation: 956
So to give a more accurate answer to navasd answer, Username was getting overwritten by the Guard.php
in the Illuminate\Auth\Guard.php
file.
It stores sessions by name and for some reason it was storing the Username as null and overwriting my Session::put('Username')
session variable. Renaming it to 'username' has worked though.
Upvotes: 0