How does Auth::user()->name and Auth::user()->email work
I have a blade view for logged in users
To display my users name and email I do this
<p>{{ Auth::user()->name }}</p><br>
<p>{{ Auth::user()->email }}</p>
But what happens in the backround?
Does Laravel do two querys? One to fetch the users name and one to fetch the email?
I just wonder if I should contionue to do like the above code or just fetch alla data in need in the controller with one query.
Auth loads the record when the user is authenticated, so its not doing it in response to either of your blade tags. It can then use the loaded model for all logged-in user queries.
@Snapey I tested it myself, and there is no query on the users table (at least according to Clockwork) unless you have one or more reference to Auth::user(), and then it is only queried once.