How to get the session id stored in the database?

I am trying to add additional information to the session table by creating another model Sessions. I use the approach detailed in the following question:

Laravel Session Table Adds Additional Column

Table

Fields:

  • id - varchar (50) - laravel stores 40 characters here.
  • payload - mediumtext - usually a string of 265 characters
  • last_activity - int (11)
  • user_id - bigint (20)
  • type - varchar (15) - default ('biz')
  • created_at - timestamp - default (CURRENT_TIMESTAMP)

Model

class Sessions extends BaseModel
{
    protected $table = 'sessions';
    protected $fillable = array(
        'id', 
        'payload', 
        'last_activity', 
        'user_id', 
        'type', 
        'created_at');

    public static function getCurrent()
    {
        return Sessions::find(Session::getId());
    }
} 

controller

public function postLogin()
{
    if (\Auth::biz()->attempt(\Input::only(array('email', 'password')), 
        \Input::get('persist', 'no') == 'yes')) {
        $session = Sessions::getCurrent(); // returns NULL
        // fields getting values
        $session->save();
        return \Redirect::route('marketer.home');
    } else {
        return \Redirect::back()->withInput()->with('loginFail', true);
    }
}

I am using laravel v4.2.16 with database session management. The function Session::getId()does not return the identifier stored in the database, so I can not get the current session with the modal method my Sessions::getCurrent().

, .

+4
2

:

$user = \Auth::user(); in the view file

$user :

echo "<pre>";
print_r($user);
echo "</pre>";
exit;

, .

0

static Session::unguard(); , Session::reguard();

0

Source: https://habr.com/ru/post/1569417/


All Articles