1 | <?php |
||
2 | |||
3 | namespace App; |
||
4 | |||
5 | use App\Events\UserSaved; |
||
6 | use Illuminate\Notifications\Notifiable; |
||
7 | use Illuminate\Foundation\Auth\User as Authenticatable; |
||
8 | |||
9 | class User extends Authenticatable |
||
10 | { |
||
11 | use Notifiable; |
||
0 ignored issues
–
show
introduced
by
![]() |
|||
12 | |||
13 | /** |
||
14 | * The event map for the model. |
||
15 | * |
||
16 | * @var array |
||
17 | */ |
||
18 | protected $dispatchesEvents = [ |
||
19 | 'saved' => UserSaved::class |
||
20 | ]; |
||
21 | |||
22 | /** |
||
23 | * The attributes that are mass assignable. |
||
24 | * |
||
25 | * @var array |
||
26 | */ |
||
27 | protected $fillable = [ |
||
28 | 'name', 'email', 'password', |
||
29 | ]; |
||
30 | |||
31 | /** |
||
32 | * The attributes that should be hidden for arrays. |
||
33 | * |
||
34 | * @var array |
||
35 | */ |
||
36 | protected $hidden = [ |
||
37 | 'password', 'remember_token', |
||
38 | ]; |
||
39 | |||
40 | /** |
||
41 | * A user has many projects |
||
42 | * |
||
43 | * @return \Illuminate\Database\Eloquent\Relations\HasMany |
||
44 | */ |
||
45 | public function projects() |
||
46 | { |
||
47 | return $this->hasMany(Project::class); |
||
48 | } |
||
49 | |||
50 | /** |
||
51 | * A user has many timelogs |
||
52 | * |
||
53 | * @return \Illuminate\Database\Eloquent\Relations\HasMany |
||
54 | */ |
||
55 | public function timelogs() |
||
56 | { |
||
57 | return $this->hasMany(TimeLog::class); |
||
58 | } |
||
59 | |||
60 | /** |
||
61 | * A user has many settings |
||
62 | * |
||
63 | * @return \Illuminate\Database\Eloquent\Relations\HasOne |
||
64 | */ |
||
65 | public function settings() |
||
66 | { |
||
67 | return $this->hasOne(UserSetting::class); |
||
68 | } |
||
69 | |||
70 | /** |
||
71 | * A user has many milestones |
||
72 | * |
||
73 | * @return \Illuminate\Database\Eloquent\Relations\HasMany |
||
74 | */ |
||
75 | public function milestones() |
||
76 | { |
||
77 | return $this->hasMany(ProjectMilestone::class); |
||
78 | } |
||
79 | |||
80 | /** |
||
81 | * Get the total time logged for this user |
||
82 | * |
||
83 | * @return int |
||
84 | */ |
||
85 | public function getTotalTimeLoggedAttribute() |
||
86 | { |
||
87 | return $this->timelogs->sum('number_of_seconds'); |
||
88 | } |
||
89 | } |
||
90 |