1

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.

Shafi
  • 1,850
  • 3
  • 22
  • 44
  • The only safe option would be to store only the user id. By storing any other user information in multiple tables creates data inconsistencies and with these tables growth comes a lot of headaches.. – Mihai Matei Mar 30 '16 at 13:24
  • @MateiMihai, I edited the description. May be this time it is more clear to understand what I wanted to know. – Shafi Mar 30 '16 at 13:33
  • Possible duplicate of [Laravel: Auth::user()->id tying to get a property of a non-object](http://stackoverflow.com/questions/17835886/laravel-authuser-id-tying-to-get-a-property-of-a-non-object) – Syed mohamed aladeen Mar 30 '16 at 14:13

1 Answers1

1

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;

jfgonzal
  • 28
  • 6