Change variable value of Orange Session

Asked

Viewed 624 times

1

I have a problem with how to change the session variable in Laravel. When the user logs in, some variables are set in the session, one of them is the user name. In a given form, there is the option to change the user data, if he changes the name, the value that was set in the session should be changed but I do not know how to do it.

session(
         [
          'id_usuario' => $usuario[0]->id_user,
          'usuario' => $usuario[0]->nome
         ]
);

How I change the session array user field?

1 answer

0

As you are doing already changes the user name in the session. If you want to change/set only the name you can do:

session(['id_usuario' => 'novo nome do usuario aqui']);

If you are reading the form name you need to use $request->input and specifying the form field that has the name:

session(['id_usuario' => $request->input('nome')]);

The nome in this last example corresponds to the attribute name form field bearing the name:

<form>
    ...
    <input type="text" name="nome"/>
    <!-- Corresponde a ------^  -->

Another alternative would be to use the method put:

$request->session()->put('id_usuario', $request->input('nome'));

Documentation for the Laravel Session

  • For it is Isac, when I refresh the page, the session is terminated, thus, not counting that if I do dd(Session('Blabla')) it returns null.

  • @Felipepaz and dd(session()->all()); and dd($usuario) give what ?

  • Simply gives null for all session data.

  • @Felipepaz and dd($usuario) gives what ?

Browser other questions tagged

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