Bristol SU Support Package
User.php
Go to the documentation of this file.
1 <?php
2 
3 namespace BristolSU\Support\User;
4 
6 use Illuminate\Contracts\Auth\MustVerifyEmail as MustVerifyEmailContract;
7 use Illuminate\Foundation\Auth\User as Authenticatable;
11 
15 class User extends Authenticatable implements MustVerifyEmailContract
16 {
18 
24  protected $fillable = [
25  'control_id'
26  ];
27 
33  protected $hidden = [
34  'password', 'remember_token'
35  ];
36 
42  public function controlId(): int
43  {
44  return (int) $this->control_id;
45  }
46 
52  public function controlUser()
53  {
54  return app(\BristolSU\ControlDB\Contracts\Repositories\User::class)->getById($this->controlId());
55  }
56 
62  public function routeNotificationForMail()
63  {
64  return $this->controlUser()->data()->email();
65  }
66 
73  public function getEmailForVerification()
74  {
75  $email = $this->controlUser()->data()->email();
76  if(!$email) {
77  throw ValidationException::withMessages([
78  'identifier' => 'Your email has not been set.'
79  ]);
80  }
81  return $email;
82  }
83 
90  public function getEmailForPasswordReset()
91  {
92  $email = $this->controlUser()->data()->email();
93  if(!$email) {
94  throw ValidationException::withMessages([
95  'identifier' => 'Your email has not been set.'
96  ]);
97  }
98  return $email;
99  }
100 }