Session in Laravel 5

1

In my controller, I log in as follows:

if(!empty($input['user'])) {
            $result = $this->userRepository->searchuser($input['user']); //Busca o usuario pelo login
            // dd($result['data']['user']);

            if ($result['success']) {
                $request->session()->put('user', $result['data']['user']); //Armazeno os dados do usuario numa sessão

                if (Auth::loginUsingId($result['data']['user']->id)) {
                    return redirect('/');//faz o login e redireciona para a rota
                }
            } 
        }
    }
    return view('web::login');

And in another controller I retrieve the value of the session:

if($request->session()->has('user')) {
        $user = $request->session()->get('user');
    }        

    return view ('web::profile')->with(compact('user'));

The problem is that sometimes the value is recorded and sometimes not, hence when I retrieve the value in the view, it gives error by not finding the data of the session. Another problem is that when it works and it can retrieve session values, after I click on a link in a route ( <a href="/home"></a> ), the session expires. Can any Jedi in laravel help me?

    
asked by anonymous 06.12.2017 / 16:17

1 answer

1

You can use your own Laravel class to get data from the authenticated user.

\Auth::user()
    
08.12.2017 / 11:53