Reputation: 2098
How laravel Auth:user()
or Auth:id()
works
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 ;)
Upvotes: 12
Views: 26359
Reputation: 1104
You can find this method in Auth\SessionGuard class :
Authenticatable|null user()
Get the currently authenticated user.
Return Value Authenticatable|null
Check it out: https://laravel.com/api/5.7/Illuminate/Auth/SessionGuard.html#method_user
Upvotes: 1
Reputation: 526
Here's my attempt at figuring out what actually happens on an Auth::user()
call:
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)
Container::offsetGet(auth)
Application::make(auth)
Container::getAlias(auth) return 'auth'
Container::make(auth)
Container::resolve(auth)
yadda, yadda, yadda
See in 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
Upvotes: 8
Reputation: 1028
laravel uses session for authentication.if you are beginer in laravel then must read following link:
https://laravel.com/docs/5.4/authentication
i think its help you
Upvotes: 1
Reputation: 172
Did you read this? Its a good guide to start with
https://laravel.com/docs/5.4/authentication
Upvotes: 2