Bristol SU Support Package
UserRepository.php
Go to the documentation of this file.
1 <?php
2 
3 namespace BristolSU\Support\User;
4 
6 use BristolSU\Support\User\Contracts\UserRepository as UserRepositoryContract;
9 
13 class UserRepository implements UserRepositoryContract
14 {
15 
21  public function all()
22  {
23  return User::all();
24  }
25 
33  public function getFromControlId(int $controlId): User
34  {
35  return User::where('control_id', $controlId)->firstOrFail();
36  }
37 
49  public function create(array $attributes): User
50  {
51  return User::create($attributes);
52  }
53 
61  public function getWhereEmail($email): User
62  {
63  $dataUser = app(DataUser::class)->getWhere(['email' => $email]);
64  $controlUser = app(\BristolSU\ControlDB\Contracts\Repositories\User::class)->getByDataProviderId($dataUser->id());
65  return $this->getFromControlId($controlUser->id());
66  }
67 
75  public function getFromRememberToken(string $token): User
76  {
77  return User::where('remember_token', $token)->firstOrFail();
78  }
79 
83  public function getById(int $id): User
84  {
85  return User::findOrFail($id);
86  }
87 
94  public function setRememberToken(int $id, $token): void
95  {
96  $user = $this->getById($id);
97  $user->setRememberToken($token);
98  $user->save();
99  }
100 
101 
102 }