P
P
photosho2016-01-19 12:32:59
Laravel
photosho, 2016-01-19 12:32:59

How does \Auth::user() work?

Hello. The following question arose: there are several functions that are called alternately in different places when generating the page code. Each of them must work with an authorized user object ( \Auth::user()). Is there a performance difference between getting that object every time and saving it to some global variable and getting it from there? Where does the data about such an object come from?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
WebDev, 2016-01-19
@photosho

It makes no sense to take out in a global variable. Take each time from \Auth::user()
Part of the function description:

// If we've already retrieved the user for the current request we can just
        // return it back immediately. We do not want to fetch the user data on
        // every call to this method because that would be tremendously slow.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question