Bristol SU Support Package
UserWebAuthentication.php
Go to the documentation of this file.
1 <?php
2 
3 namespace BristolSU\Support\User;
4 
6 use Illuminate\Contracts\Auth\Factory as AuthFactory;
7 
12 {
13 
19  private $auth;
20 
24  public function __construct(AuthFactory $auth)
25  {
26  $this->auth = $auth;
27  }
28 
34  public function getUser(): ?User
35  {
36  if ($this->auth->guard('web')->check()) {
37  return $this->auth->guard('web')->user();
38  }
39  return null;
40  }
41 
47  public function setUser(User $user)
48  {
49  $this->auth->guard('web')->login($user);
50  }
51 
57  public function logout(): void
58  {
59  $this->auth->guard('web')->logout();
60  }
61 }