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
|
|
|
class User extends Authenticatable |
15
|
|
|
{ |
16
|
|
|
use Notifiable; |
|
|
|
|
17
|
|
|
use SoftDeletes; |
18
|
|
|
use CrudTrait; |
|
|
|
|
19
|
|
|
use HasRoles; |
|
|
|
|
20
|
|
|
use LogsActivity; |
21
|
|
|
|
22
|
|
|
protected $guarded = ['id']; |
23
|
|
|
|
24
|
|
|
protected static bool $logFillable = true; |
25
|
|
|
|
26
|
|
|
protected $hidden = ['password', 'remember_token']; |
27
|
|
|
|
28
|
|
|
protected $dispatchesEvents = [ |
29
|
|
|
'deleting' => UserDeleting::class, |
30
|
|
|
]; |
31
|
|
|
|
32
|
|
|
public function getEmailForPasswordReset() : string |
33
|
|
|
{ |
34
|
|
|
return $this->email; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function isTeacher() |
38
|
|
|
{ |
39
|
|
|
return Teacher::whereId($this->id)->count() > 0; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function isStudent() |
43
|
|
|
{ |
44
|
|
|
return Student::whereId($this->id)->count() > 0; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function student() |
48
|
|
|
{ |
49
|
|
|
return $this->hasOne(Student::class, 'id', 'id'); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function teacher() |
53
|
|
|
{ |
54
|
|
|
return $this->hasOne(Teacher::class, 'id', 'id'); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function getFirstnameAttribute($value) |
58
|
|
|
{ |
59
|
|
|
return Str::title($value); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function getLastnameAttribute($value) |
63
|
|
|
{ |
64
|
|
|
return Str::upper($value); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
public function getNameAttribute() |
68
|
|
|
{ |
69
|
|
|
return $this->firstname.' '.$this->lastname; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
public function getForceUpdateAttribute() |
73
|
|
|
{ |
74
|
|
|
return $this->force_update ?? null; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
public function setEmailAttribute($value) |
78
|
|
|
{ |
79
|
|
|
$this->attributes['email'] = strtolower($value); |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|