3

I am developing a project using laravel 5.2. I use default authentication in this project by running this command.

php artisan make:auth

Everything is working great. Now I want to put some data in session after authenticate the user. I can not find the place where I put my code to store data in session after authenticate the user. I googled but not found any solution.

3 Answers 3

1

Finally I got answer from another question. Here i post the solution for who are looking this type of solution

https://stackoverflow.com/a/36491235/2738927

Sign up to request clarification or add additional context in comments.

4 Comments

This is solution for 5.1, you're using 5.2
Its working for me now. If I face any problem I will try with your solution
Just curious what exact version do you use? Because in 5.2.45 there is no authenticated() method.
My laravel version is 5.2.41
0

You can check whether the user is logged in or not using the following code.

if (Auth::check()) {
    // The user is logged in...
}

Then you can use the session helper class to set the required value in session.

session()->set('session_key', 'session_value');

Additionally, you can remove the session using the forget method.

session()->forget('session_key');

Resources to read.

https://laravel.com/docs/5.3/authentication

https://laravel.com/docs/5.3/session

https://laravel.com/docs/5.3/helpers#method-session

Comments

0

In 5.2 you need to override login() method from Illuminate\Foundation\Auth\AuthenticatesUsers trait in AuthController.php.

To set data use session() helper in login() method:

session(['key' => 'value']);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.