I have fresh Laravel 5.3 installation. Just used the php artisan make:auth to get started with built in auth functionalities. All works fine, and after login the Auth::check() returns true, Auth::user() return the user's data and Auth::id() gives the logged in user's id.
What bothering me is that when I have only this line
$userId = Auth:id();
in my controller's action (and no other code elsewhere associated with Auth) in the Debugger panel's "Queries" tab I see the following query
select * from `users` where `users`.`id` = '34' limit 1
This extra query is highly undesirable to me (especially the select all part), as I need the user's id to make a query, selecting specific fields from users table, as well as to join it with another tables. For performance reasons I do not want to do double query.
So, is there a way to tell Laravel to save the logged in user's id in session(if it is not being saved) and get the id of the logged in user directly from session - without making any query to the database.
Thanks
from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2j5rqT3
via IFTTT
Aucun commentaire:
Enregistrer un commentaire