1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Models; |
4
|
|
|
|
5
|
|
|
use App\Events\UserDeleting; |
6
|
|
|
use Backpack\CRUD\app\Models\Traits\CrudTrait; |
7
|
|
|
use Illuminate\Database\Eloquent\SoftDeletes; |
8
|
|
|
use Illuminate\Foundation\Auth\User as Authenticatable; |
9
|
|
|
use Illuminate\Notifications\Notifiable; |
10
|
|
|
use Illuminate\Support\Str; |
11
|
|
|
use Spatie\Activitylog\Traits\LogsActivity; |
12
|
|
|
use Spatie\Permission\Traits\HasRoles; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* @mixin IdeHelperUser |
16
|
|
|
*/ |
17
|
|
|
class User extends Authenticatable |
18
|
|
|
{ |
19
|
|
|
use Notifiable; |
|
|
|
|
20
|
|
|
use SoftDeletes; |
21
|
|
|
use CrudTrait; |
|
|
|
|
22
|
|
|
use HasRoles; |
|
|
|
|
23
|
|
|
use LogsActivity; |
24
|
|
|
|
25
|
|
|
protected $guarded = ['id']; |
26
|
|
|
|
27
|
|
|
protected static bool $logFillable = true; |
28
|
|
|
|
29
|
|
|
protected $hidden = ['password', 'remember_token']; |
30
|
|
|
|
31
|
|
|
protected $dispatchesEvents = [ |
32
|
|
|
'deleting' => UserDeleting::class, |
33
|
|
|
]; |
34
|
|
|
|
35
|
|
|
public function getEmailForPasswordReset() : string |
36
|
|
|
{ |
37
|
|
|
return $this->email; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function isTeacher() |
41
|
|
|
{ |
42
|
|
|
return Teacher::whereId($this->id)->count() > 0; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function isStudent() |
46
|
|
|
{ |
47
|
|
|
return Student::whereId($this->id)->count() > 0; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function student() |
51
|
|
|
{ |
52
|
|
|
return $this->hasOne(Student::class, 'id', 'id'); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function teacher() |
56
|
|
|
{ |
57
|
|
|
return $this->hasOne(Teacher::class, 'id', 'id'); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function getFirstnameAttribute($value) |
61
|
|
|
{ |
62
|
|
|
return Str::title($value); |
|
|
|
|
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
public function getLastnameAttribute($value) |
66
|
|
|
{ |
67
|
|
|
return Str::upper($value); |
|
|
|
|
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function getNameAttribute() |
71
|
|
|
{ |
72
|
|
|
return $this->firstname.' '.$this->lastname; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
public function getIdnumberAttribute() |
76
|
|
|
{ |
77
|
|
|
if ($this->isStudent()) { |
78
|
|
|
return $this->student->idnumber; |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
public function getAddressAttribute() |
83
|
|
|
{ |
84
|
|
|
if ($this->isStudent()) { |
85
|
|
|
return $this->student->address; |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
public function getBirthdateAttribute() |
90
|
|
|
{ |
91
|
|
|
if ($this->isStudent()) { |
92
|
|
|
return $this->student->birthdate; |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
public function getTeacherIdAttribute() |
97
|
|
|
{ |
98
|
|
|
return $this->teacher->id ?? null; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
public function getStudentIdAttribute() |
102
|
|
|
{ |
103
|
|
|
return $this->student->id ?? null; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
public function getForceUpdateAttribute() |
107
|
|
|
{ |
108
|
|
|
return $this->force_update ?? null; |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
public function setEmailAttribute($value) |
112
|
|
|
{ |
113
|
|
|
$this->attributes['email'] = strtolower($value); |
114
|
|
|
} |
115
|
|
|
} |
116
|
|
|
|