laravel `Auth:user()` 或 `Auth:id()` 如何工作
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/42486890/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How laravel `Auth:user()` or `Auth:id()` works
提问by GRESPL Nagpur
How laravel Auth:user()
or Auth:id()
works
laravelAuth:user()
或如何Auth:id()
工作
Is it resides in session or database.
它驻留在会话或数据库中。
I searched but not get good article.
我搜索但没有得到好的文章。
Please help to understand. I know I will get many down-votes ;)
请帮助理解。我知道我会得到很多反对票;)
采纳答案by pascal zoet
Did you read this? Its a good guide to start with
你读过这个吗?这是一个很好的入门指南
回答by Rob
Here's my attempt at figuring out what actually happens on an Auth::user()
call:
这是我试图弄清楚Auth::user()
通话中实际发生的事情:
Auth::user()
Illuminate\Support\Facades\Auth
extends Illuminate\Support\Facades\Facade
Facade::__callStatic('user')
static::getFacadeRoot()
resolveFacadeInstance(static::getFacadeAccessor == 'auth' (from Auth class))
return static::$app[$name];
static::$app is instance of Illuminate\Foundation\Application
extends Illuminate\Container\Container
which implements ArrayAccess
(which is why $obj[]
syntax works)
哪个实现ArrayAccess
(这就是$obj[]
语法起作用的原因)
Container::offsetGet(auth)
Application::make(auth)
Container::getAlias(auth) return 'auth'
Container::make(auth)
Container::resolve(auth)
yadda, yadda, yadda
See in Application::registerCoreContainerAliases
yadda, yadda, yadda 见 Application::registerCoreContainerAliases
'auth' = Illuminate\Auth\AuthManager
AuthManager::user() = AuthManager::__call = $this->guard()->user()
AuthManager::guard(web)
AuthManager::resolve(web) (see config/auth.php)
AuthManager::createSessionDriver() returns new Illuminate\Auth\SessionGuard
SessionGuard::user() // <---- this is what actually get's called, based on default config
回答by Jigneshsinh Rathod
laravel uses session for authentication.if you are beginer in laravel then must read following link:
laravel 使用 session 进行身份验证。如果您是 laravel 的初学者,那么必须阅读以下链接:
https://laravel.com/docs/5.4/authentication
https://laravel.com/docs/5.4/authentication
i think its help you
我认为它可以帮助你
回答by Ahmed Essam
You can find this method in Auth\SessionGuard class :
您可以在 Auth\SessionGuard 类中找到此方法:
Authenticatable|null user()
Get the currently authenticated user.
Return Value Authenticatable|null
可验证|空用户()
获取当前经过身份验证的用户。
返回值可验证|null
Check it out: https://laravel.com/api/5.7/Illuminate/Auth/SessionGuard.html#method_user
检查一下:https: //laravel.com/api/5.7/Illuminate/Auth/SessionGuard.html#method_user