How laravel `Auth:user()` or `Auth:id()` works
Here's my attempt at figuring out what actually happens on an Auth::user()
call:
Auth::user()Illuminate\Support\Facades\Authextends Illuminate\Support\Facades\FacadeFacade::__callStatic('user')static::getFacadeRoot()resolveFacadeInstance(static::getFacadeAccessor == 'auth' (from Auth class))return static::$app[$name];static::$app is instance of Illuminate\Foundation\Applicationextends 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, yaddaSee in Application::registerCoreContainerAliases
'auth' = Illuminate\Auth\AuthManagerAuthManager::user() = AuthManager::__call = $this->guard()->user()AuthManager::guard(web)AuthManager::resolve(web) (see config/auth.php)AuthManager::createSessionDriver() returns new Illuminate\Auth\SessionGuardSessionGuard::user() // <---- this is what actually get's called, based on default config
Did you read this? Its a good guide to start with
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