academico-sis /
academico
| 1 | <?php |
||
| 2 | |||
| 3 | namespace App\Models; |
||
| 4 | |||
| 5 | use App\Events\UserDeleting; |
||
| 6 | use App\Events\UserUpdated; |
||
| 7 | use Backpack\CRUD\app\Models\Traits\CrudTrait; |
||
| 8 | use Illuminate\Database\Eloquent\SoftDeletes; |
||
| 9 | use Illuminate\Foundation\Auth\User as Authenticatable; |
||
| 10 | use Illuminate\Notifications\Notifiable; |
||
| 11 | use Illuminate\Support\Str; |
||
| 12 | use Spatie\Activitylog\Traits\LogsActivity; |
||
| 13 | use Spatie\Permission\Traits\HasRoles; |
||
| 14 | |||
| 15 | /** |
||
| 16 | * @mixin IdeHelperUser |
||
| 17 | */ |
||
| 18 | class User extends Authenticatable |
||
| 19 | { |
||
| 20 | use Notifiable; |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 21 | use SoftDeletes; |
||
| 22 | use CrudTrait; |
||
|
0 ignored issues
–
show
|
|||
| 23 | use HasRoles; |
||
|
0 ignored issues
–
show
|
|||
| 24 | use LogsActivity; |
||
| 25 | |||
| 26 | protected $guarded = ['id']; |
||
| 27 | |||
| 28 | protected static bool $logFillable = true; |
||
| 29 | |||
| 30 | protected $hidden = ['password', 'remember_token']; |
||
| 31 | |||
| 32 | protected $dispatchesEvents = [ |
||
| 33 | 'deleting' => UserDeleting::class, |
||
| 34 | 'updated' => UserUpdated::class, |
||
| 35 | ]; |
||
| 36 | |||
| 37 | public function getEmailForPasswordReset(): string |
||
| 38 | { |
||
| 39 | return $this->email; |
||
| 40 | } |
||
| 41 | |||
| 42 | public function isTeacher() |
||
| 43 | { |
||
| 44 | return Teacher::whereId($this->id)->count() > 0; |
||
| 45 | } |
||
| 46 | |||
| 47 | public function isStudent() |
||
| 48 | { |
||
| 49 | return Student::whereId($this->id)->count() > 0; |
||
| 50 | } |
||
| 51 | |||
| 52 | public function student() |
||
| 53 | { |
||
| 54 | return $this->hasOne(Student::class, 'id', 'id'); |
||
| 55 | } |
||
| 56 | |||
| 57 | public function teacher() |
||
| 58 | { |
||
| 59 | return $this->hasOne(Teacher::class, 'id', 'id'); |
||
| 60 | } |
||
| 61 | |||
| 62 | public function getFirstnameAttribute($value) |
||
| 63 | { |
||
| 64 | return Str::title($value); |
||
| 65 | } |
||
| 66 | |||
| 67 | public function getLastnameAttribute($value) |
||
| 68 | { |
||
| 69 | return Str::upper($value); |
||
| 70 | } |
||
| 71 | |||
| 72 | public function getNameAttribute() |
||
| 73 | { |
||
| 74 | return $this->firstname.' '.$this->lastname; |
||
| 75 | } |
||
| 76 | |||
| 77 | public function getForceUpdateAttribute() |
||
| 78 | { |
||
| 79 | return $this->force_update ?? null; |
||
| 80 | } |
||
| 81 | |||
| 82 | public function setEmailAttribute($value) |
||
| 83 | { |
||
| 84 | $this->attributes['email'] = strtolower($value); |
||
| 85 | } |
||
| 86 | } |
||
| 87 |