Passed
Push — master ( a643fc...0bc75b )
by Thomas
08:11
created

User::getAddressAttribute()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 2
c 0
b 0
f 0
nc 2
nop 0
dl 0
loc 4
rs 10
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;
0 ignored issues
show
Bug introduced by
The trait Illuminate\Notifications\Notifiable requires the property $email which is not provided by App\Models\User.
Loading history...
17
    use SoftDeletes;
18
    use CrudTrait;
0 ignored issues
show
introduced by
The trait Backpack\CRUD\app\Models\Traits\CrudTrait requires some properties which are not provided by App\Models\User: $fakeColumns, $identifiableAttribute, $Type
Loading history...
19
    use HasRoles;
0 ignored issues
show
introduced by
The trait Spatie\Permission\Traits\HasRoles requires some properties which are not provided by App\Models\User: $name, $map, $permissions, $roles, $guard_name
Loading history...
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