Create session variable when logging in - Laravel

Asked

Viewed 4,772 times

0

Good morning, I’m going through a site made in Laravel, which I didn’t do. I need to do the following:

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

How can I do that?

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

1 answer

4


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

Then I will show what each method does in relation to that class:

Session::put - Adds one or more values in the session. You can use "dot Notation" to make it easier to create multidimensional arrays within the session.

Example:

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

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

Session::get - Get the data from a session index. You can also use the 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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.