简体   繁体   中英

get logged in user info in laravel

I am working in a laravel app. It is laravel 5.2.

For some user's actions, I need the current user information to store in database. For this now I am sending the informations of logged in user when user does those actions. Informations like email or user_id which are already in database.

But I have a feel that, this is not a good approach. Someone can easily change the info while sending to server. So is there any option given by laravel or any other safe option to do? If yes, how can I get informations in server end?

Edited: As per comment, I do not want to store the user information again. I have to keep reference with some other information in other table. I want to know a way to get the username, email or userId who is logged in and made the action.

If you want to get the users information in the controller, assuming that the user is logged in, you can always use $user = Auth::user(); , this will return the object of the current user.

Also, don't forget to use at the top use Illuminate\\Support\\Facades\\Auth;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM