1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace DoeSangue\Models; |
4
|
|
|
|
5
|
|
|
use Illuminate\Notifications\Notifiable; |
6
|
|
|
use Illuminate\Foundation\Auth\User as Authenticatable; |
7
|
|
|
use DoeSangue\Models\Campaign; |
8
|
|
|
use DoeSangue\Models\Donor; |
9
|
|
|
use DoeSangue\Models\Invite; |
10
|
|
|
use DoeSangue\Models\Comment; |
11
|
|
|
|
12
|
|
|
class User extends Authenticatable |
13
|
|
|
{ |
14
|
|
|
use Notifiable; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* The attributes that are mass assignable. |
18
|
|
|
* |
19
|
|
|
* @var array |
20
|
|
|
*/ |
21
|
|
|
protected $fillable = [ |
22
|
|
|
'first_name', |
23
|
|
|
'last_name', |
24
|
|
|
'email', |
25
|
|
|
'username', |
26
|
|
|
'phone', |
27
|
|
|
'bio', |
28
|
|
|
'birthdate', |
29
|
|
|
'active', |
30
|
|
|
'password', |
31
|
|
|
]; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* The attributes that should be hidden for arrays. |
35
|
|
|
* |
36
|
|
|
* @var array |
37
|
|
|
*/ |
38
|
|
|
protected $hidden = [ |
39
|
|
|
'password', |
40
|
|
|
'remember_token', |
41
|
|
|
'created_at', |
42
|
|
|
'updated_at', |
43
|
|
|
'deleted_at', |
44
|
|
|
'id', |
45
|
|
|
'phone', |
46
|
|
|
'active' |
47
|
|
|
]; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* The dates attributes. |
51
|
|
|
* |
52
|
|
|
* @var array $dates |
53
|
|
|
*/ |
54
|
|
|
protected $dates = [ |
55
|
|
|
'created_at', 'updated_at', 'deleted_at' |
56
|
|
|
]; |
57
|
|
|
|
58
|
|
|
protected $appends = [ 'is_active' ]; |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Returns the full name of user. |
62
|
|
|
* |
63
|
|
|
* @return string |
64
|
|
|
*/ |
65
|
|
|
public function getFullNameAttribute($value) |
|
|
|
|
66
|
|
|
{ |
67
|
|
|
return ucfirst($this->first_name) . ' ' . ucfirst($this->last_name); |
|
|
|
|
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Returns the campaigns created by the user. |
72
|
|
|
* |
73
|
|
|
* @return array relationship |
74
|
|
|
* @var array |
75
|
|
|
*/ |
76
|
|
|
public function campaigns() |
77
|
|
|
{ |
78
|
|
|
return $this->hasMany(Campaign::class); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
public function donor() |
82
|
|
|
{ |
83
|
|
|
return $this->hasOne(Donor::class); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Return as Many invites created by user. |
88
|
|
|
*/ |
89
|
|
|
public function invites() |
90
|
|
|
{ |
91
|
|
|
return $this->hasMany(Invite::class); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Returns the comments created by the user. |
96
|
|
|
* |
97
|
|
|
* @return array relationship |
98
|
|
|
* @var array |
99
|
|
|
*/ |
100
|
|
|
public function comments() |
101
|
|
|
{ |
102
|
|
|
return $this->hasMany(Comment::class); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
public function getIsActiveAttribute() |
106
|
|
|
{ |
107
|
|
|
return $this->attributes['active'] == true; |
108
|
|
|
} |
109
|
|
|
} |
110
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.