Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
71.43% |
5 / 7 |
|
50.00% |
2 / 4 |
CRAP | |
0.00% |
0 / 1 |
User | |
71.43% |
5 / 7 |
|
50.00% |
2 / 4 |
4.37 | |
0.00% |
0 / 1 |
isRoot | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
scopeWhereMe | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
role | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
jsonSerialize | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | |
3 | namespace App\Models; |
4 | |
5 | use Illuminate\Contracts\Auth\MustVerifyEmail; |
6 | use Illuminate\Database\Eloquent\Factories\HasFactory; |
7 | use Illuminate\Database\Eloquent\Builder; |
8 | use Illuminate\Database\Eloquent\Relations\BelongsTo; |
9 | use Illuminate\Database\Eloquent\Relations\BelongsToMany; |
10 | use Illuminate\Foundation\Auth\User as Authenticatable; |
11 | use Illuminate\Notifications\Notifiable; |
12 | use Laravel\Passport\HasApiTokens; |
13 | |
14 | |
15 | /** |
16 | * App\Models\User |
17 | * |
18 | * @property Int $id |
19 | * @property String $first_name |
20 | * @property String $email |
21 | * @property Mixed $role |
22 | */ |
23 | class User extends Authenticatable |
24 | { |
25 | use HasApiTokens, HasFactory, Notifiable; |
26 | |
27 | /** |
28 | * The attributes that are mass assignable. |
29 | * |
30 | * @var array<string> |
31 | */ |
32 | protected $fillable = [ |
33 | 'name', |
34 | 'email', |
35 | 'password', |
36 | 'role_id', |
37 | 'provider_id', |
38 | 'provider_name', |
39 | 'google_access_token_json', |
40 | ]; |
41 | |
42 | /** |
43 | * The attributes that should be hidden for serialization. |
44 | * |
45 | * @var array<string> |
46 | */ |
47 | protected $hidden = [ |
48 | 'password', |
49 | 'remember_token', |
50 | ]; |
51 | |
52 | |
53 | /** |
54 | * The attributes that should be cast. |
55 | * |
56 | * @var array |
57 | */ |
58 | protected $casts = [ |
59 | 'email_verified_at' => 'datetime', |
60 | ]; |
61 | |
62 | |
63 | /** |
64 | * Determine if this user is root |
65 | */ |
66 | public function isRoot():bool |
67 | { |
68 | return $this->role_id === 1; |
69 | } |
70 | |
71 | |
72 | /** |
73 | * Get session user user |
74 | */ |
75 | public function scopeWhereMe(Builder $query):Builder |
76 | { |
77 | return $query->where('users.id', '=', auth()->guard('api')->user()->id); |
78 | } |
79 | |
80 | |
81 | /** |
82 | * Retreive user's role |
83 | */ |
84 | public function role():BelongsTo |
85 | { |
86 | return $this->belongsTo(Role::class, 'role_id'); |
87 | } |
88 | |
89 | |
90 | /** |
91 | * Json Serialize |
92 | * |
93 | */ |
94 | public function jsonSerialize() |
95 | { |
96 | return [ |
97 | 'id' => $this->id, |
98 | 'name' => $this->name, |
99 | 'email' => $this->email, |
100 | 'role' => $this->role, |
101 | ]; |
102 | |
103 | } // jsonSerialize |
104 | } |