1

There is default object Auth in Laravel after authification.

It contents data about current user from table Users. How can I add the additional data to this object from other related table?

Edit: So, if I am right, the object Auth is created when user is authenticated. In this moment I need to fill object by additional data.

1
  • I'm looking to do the same, did you ever get this figured out? I have the data from the user table, which is already getting selected during Auth, and data in a settings table that I also need at login. Commented Nov 14, 2016 at 20:29

1 Answer 1

2

I presume you want to retrieve a user in a controller and return it as a response, maybe json? or not, it's doesn't really matter. here what you could do

public function getUser()
{
     $user = auth()->user();

     $user->load('relationName');
     $user->load('anotherRelationName');
}
Sign up to request clarification or add additional context in comments.

3 Comments

Yes, but where I can change this? In what file?
you would to this in a controller, or some other class that is responsible for fetching data for your user. Update your question by providing some code so I have better understanding. or at least tell a bit more what you are trying to achieve?
I mean where is formed Auth object with data from user model?

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.