1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace DoeSangue\Models; |
4
|
|
|
|
5
|
|
|
use Illuminate\Notifications\Notifiable; |
6
|
|
|
use Illuminate\Foundation\Auth\User as Authenticatable; |
7
|
|
|
use Illuminate\Database\Eloquent\SoftDeletes; |
8
|
|
|
use DoeSangue\Models\Campaign; |
9
|
|
|
use DoeSangue\Models\Invite; |
10
|
|
|
use DoeSangue\Models\BloodType; |
11
|
|
|
use DoeSangue\Models\Comment; |
12
|
|
|
use DoeSangue\Uuids; |
13
|
|
|
|
14
|
|
|
class User extends Authenticatable |
15
|
|
|
{ |
16
|
|
|
use Notifiable, SoftDeletes, Uuids; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* The attributes that are mass assignable. |
20
|
|
|
* |
21
|
|
|
* @var array |
22
|
|
|
*/ |
23
|
|
|
protected $fillable = |
24
|
|
|
[ |
25
|
|
|
'first_name', |
26
|
|
|
'last_name', |
27
|
|
|
'email', |
28
|
|
|
'username', |
29
|
|
|
'phone', |
30
|
|
|
'country_code', |
31
|
|
|
'bio', |
32
|
|
|
'birthdate', |
33
|
|
|
'active', |
34
|
|
|
'password', |
35
|
|
|
'blood_type_id', |
36
|
|
|
]; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* The attributes that should be hidden for arrays. |
40
|
|
|
* |
41
|
|
|
* @var array |
42
|
|
|
*/ |
43
|
|
|
protected $hidden = |
44
|
|
|
[ |
45
|
|
|
'password', |
46
|
|
|
'uid', |
47
|
|
|
'remember_token', |
48
|
|
|
'created_at', |
49
|
|
|
'updated_at', |
50
|
|
|
'deleted_at', |
51
|
|
|
'phone', |
52
|
|
|
'active', |
53
|
|
|
'username', |
54
|
|
|
'is_active', |
55
|
|
|
'birthdate', |
56
|
|
|
'email', |
57
|
|
|
'blood_type_id' |
58
|
|
|
]; |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Indicates if the IDs are auto-incrementing. |
62
|
|
|
* |
63
|
|
|
* @var bool |
64
|
|
|
*/ |
65
|
|
|
public $incrementing = false; |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* The dates attributes. |
69
|
|
|
* |
70
|
|
|
* @var array $dates |
71
|
|
|
*/ |
72
|
|
|
protected $dates = |
73
|
|
|
[ |
74
|
|
|
'created_at', |
75
|
|
|
'updated_at', |
76
|
|
|
'deleted_at' |
77
|
|
|
]; |
78
|
|
|
|
79
|
|
|
protected $appends = |
80
|
|
|
[ |
81
|
|
|
'is_active' |
82
|
|
|
]; |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Returns the full name of user. |
86
|
|
|
* |
87
|
|
|
* @return string |
88
|
|
|
*/ |
89
|
|
|
public function getFullNameAttribute($value) |
90
|
|
|
{ |
91
|
|
|
return ucfirst($this->first_name).' '.ucfirst($this->last_name); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Get user avatar or set default.png as default. |
96
|
|
|
* |
97
|
|
|
* @return string |
98
|
|
|
*/ |
99
|
|
|
public function getAvatarAttribute($avatar) |
100
|
|
|
{ |
101
|
|
|
return asset($avatar ?: 'images/avatars/default.png'); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* Returns the campaigns created by the user. |
106
|
|
|
* |
107
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\HasMany relationship |
108
|
|
|
* @var array |
109
|
|
|
*/ |
110
|
|
|
public function campaigns() |
111
|
|
|
{ |
112
|
|
|
return $this->hasMany(Campaign::class); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* Related. |
117
|
|
|
* |
118
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
119
|
|
|
*/ |
120
|
|
|
public function bloodType() |
121
|
|
|
{ |
122
|
|
|
return $this->belongsTo(BloodType::class, 'blood_type_id'); |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* Return as Many invites created by user. |
127
|
|
|
*/ |
128
|
|
|
public function invites() |
129
|
|
|
{ |
130
|
|
|
return $this->hasMany(Invite::class); |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* Returns the comments created by the user. |
135
|
|
|
* |
136
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\HasMany relationship |
137
|
|
|
* @var array |
138
|
|
|
*/ |
139
|
|
|
public function comments() |
140
|
|
|
{ |
141
|
|
|
return $this->hasMany(Comment::class); |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
public function getIsActiveAttribute() |
145
|
|
|
{ |
146
|
|
|
return $this->attributes[ 'status' ] == "active"; |
|
|
|
|
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
/** |
150
|
|
|
* Get the route key for the model. |
151
|
|
|
* |
152
|
|
|
* @return string |
153
|
|
|
*/ |
154
|
|
|
public function getRouteKeyName() |
155
|
|
|
{ |
156
|
|
|
return 'username'; |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
/** |
160
|
|
|
* Get the user phone number |
161
|
|
|
* |
162
|
|
|
* @return string |
163
|
|
|
*/ |
164
|
|
|
public function getPhoneNumberAttribute() |
165
|
|
|
{ |
166
|
|
|
return $this->attributes[ 'country_code' ].$this->attributes[ 'phone' ]; |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
} |
170
|
|
|
|
PHP provides two ways to mark string literals. Either with single quotes
'literal'
or with double quotes"literal"
. The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (
\'
) and the backslash (\\
). Every other character is displayed as is.Double quoted string literals may contain other variables or more complex escape sequences.
will print an indented:
Single is Value
If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.
For more information on PHP string literals and available escape sequences see the PHP core documentation.