<?php namespace Illuminate\Auth; use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract; use Illuminate\Contracts\Auth\UserProvider; /** * These methods are typically the same across all guards. */ trait GuardHelpers { /** * The currently authenticated user. * * @var \Illuminate\Contracts\Auth\Authenticatable|null */ protected $user; /** * The user provider implementation. * * @var \Illuminate\Contracts\Auth\UserProvider */ protected $provider; /** * Determine if the current user is authenticated. If not, throw an exception. * * @return \Illuminate\Contracts\Auth\Authenticatable * * @throws \Illuminate\Auth\AuthenticationException */ public function authenticate() { if (! is_null($user = $this->user())) { return $user; } throw new AuthenticationException; } /** * Determine if the guard has a user instance. * * @return bool */ public function hasUser() { return ! is_null($this->user); } /** * Determine if the current user is authenticated. * * @return bool */ public function check() { return ! is_null($this->user()); } /** * Determine if the current user is a guest. * * @return bool */ public function guest() { return ! $this->check(); } /** * Get the ID for the currently authenticated user. * * @return int|string|null */ public function id() { if ($this->user()) { return $this->user()->getAuthIdentifier(); } } /** * Set the current user. * * @param \Illuminate\Contracts\Auth\Authenticatable $user * @return void */ public function setUser(AuthenticatableContract $user) { $this->user = $user; return $this; } /** * Forget the current user. * * @return $this */ public function forgetUser() { $this->user = null; return $this; } /** * Get the user provider used by the guard. * * @return \Illuminate\Contracts\Auth\UserProvider */ public function getProvider() { return $this->provider; } /** * Set the user provider used by the guard. * * @param \Illuminate\Contracts\Auth\UserProvider $provider * @return void */ public function setProvider(UserProvider $provider) { $this->provider = $provider; } }
Name | Type | Size | Permission | Actions |
---|---|---|---|---|
.github | Folder | 0755 |
|
|
Access | Folder | 0755 |
|
|
Console | Folder | 0755 |
|
|
Events | Folder | 0755 |
|
|
Listeners | Folder | 0755 |
|
|
Middleware | Folder | 0755 |
|
|
Notifications | Folder | 0755 |
|
|
Passwords | Folder | 0755 |
|
|
.gitattributes | File | 54 B | 0644 |
|
AuthManager.php | File | 8.59 KB | 0644 |
|
AuthServiceProvider.php | File | 3.15 KB | 0644 |
|
Authenticatable.php | File | 1.83 KB | 0644 |
|
AuthenticationException.php | File | 1.13 KB | 0644 |
|
CreatesUserProviders.php | File | 2.5 KB | 0644 |
|
DatabaseUserProvider.php | File | 4.76 KB | 0644 |
|
EloquentUserProvider.php | File | 6.43 KB | 0644 |
|
GenericUser.php | File | 2.62 KB | 0644 |
|
GuardHelpers.php | File | 2.67 KB | 0644 |
|
LICENSE.md | File | 1.07 KB | 0644 |
|
MustVerifyEmail.php | File | 1 KB | 0644 |
|
Recaller.php | File | 1.93 KB | 0644 |
|
RequestGuard.php | File | 2.16 KB | 0644 |
|
SessionGuard.php | File | 27.42 KB | 0644 |
|
TokenGuard.php | File | 3.51 KB | 0644 |
|
composer.json | File | 1.28 KB | 0644 |
|