简体   繁体   English

Laravel 5.3-5.4 $ request-> user();之间的区别 和Auth :: user();

[英]Laravel 5.3-5.4 The Difference between $request->user(); and Auth::user();

I was reviewing some of the code logic on my system and wondered about some things. 我正在查看系统上的一些代码逻辑,并对某些事情感到好奇。 After a person has logged onto the system you can either use $request->user(); 一个人登录系统后,您可以使用$request->user(); or Auth::user(); Auth::user(); to get the user object. 获取用户对象。

My questions are: 我的问题是:

  1. What are the key differences between the two other than the obvious ones? 除了显而易见的区别,两者之间的主要区别是什么?
  2. Is the user being pulled from the database in both cases or is one pulling the user object from some stored cache? 在两种情况下都是从数据库中拉出用户,还是从某种存储的高速缓存中拉出用户对象?
  3. Are both cases leveraging passport's functionality to get the user from the database? 两种情况都利用护照的功能从数据库中获取用户吗? or is it being pulled from a mystical storage land that is difficult to find? 还是将其从难以找到的神秘仓库中拉出来?

Thanks in advance, Cheers! 预先感谢,干杯!

Let me give you a brief description: 让我给你一个简短的描述:

Auth::user(); holds the credentials or you can say the information when a user logs into application using Auth . 拥有凭据,或者当用户使用Auth登录应用程序时您可以说出这些信息。

When the user is logged successfully, it's credentials are stored in the form of cookies or sessions that are destroyed after logout. 成功登录用户后,其凭据将以cookiessessions的形式存储,并在注销后销毁。

No it is not pulled from database. 不,它不是从数据库中提取的。 The logged in user details are stored in session and pulled from there. 登录的用户详细信息存储在session然后从那里拉出。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM