Create session variable when logging in - Laravel

0

Good morning, I'm working on a site made in Laravel, which I did not do. I need to do the following:

When the user logs in, I want to get a specific value (column "idLoja") from that user in the database, and create a session variable so that I can use that variable on other pages. >

How can I do this?

Note: I do not know much about laravel. I think the site was made in Laravel 4.

    
asked by anonymous 25.02.2016 / 20:08

1 answer

3

In Laravel 4 , to use sessions, you should use the Session class.

Next, I'll show you what each method does for this class:

Session::put - Adds one or more values to the session. You can use the dot notation to facilitate the creation of multidimensional arrays within the session.

Example:

Session::put('usuario', ['nome' => 'Wallace']);

Session::put('usuario.nome', 'Wallace');

Session::get - Gets the data from a session index. You can also use DotNotation .

  $usuario = Session::get('usuario');

  var_dump($usuario['nome']);

  var_dump(Session::get('usuario.nome'));

Session::flush - Removes all session data.

Session::forget - Removes session-specific values:

  Session::forget('usuario.nome')

See more on the Laravel - Session page

    
29.04.2016 / 14:15