Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
85.71% covered (warning)
85.71%
12 / 14
75.00% covered (warning)
75.00%
6 / 8
CRAP
0.00% covered (danger)
0.00%
0 / 1
User
85.71% covered (warning)
85.71%
12 / 14
75.00% covered (warning)
75.00%
6 / 8
8.19
0.00% covered (danger)
0.00%
0 / 1
 casts
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
1 / 1
1
 tenant
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 store
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 influencer
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 isAdmin
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 isMainAdmin
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 isInfluencer
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 isActive
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3namespace App\Models;
4
5use App\Enums\Status;
6use App\Enums\UserRole;
7use Illuminate\Database\Eloquent\Factories\HasFactory;
8use Illuminate\Database\Eloquent\Relations\BelongsTo;
9use Illuminate\Database\Eloquent\Relations\HasOne;
10use Illuminate\Foundation\Auth\User as Authenticatable;
11use Illuminate\Notifications\Notifiable;
12
13class User extends Authenticatable
14{
15    use HasFactory, Notifiable;
16
17    protected $fillable = [
18        'tenant_id', 'store_id', 'name', 'email', 'password', 'role', 'status', 'last_login_at',
19    ];
20
21    protected $hidden = ['password', 'remember_token'];
22
23    protected function casts(): array
24    {
25        return [
26            'email_verified_at' => 'datetime',
27            'last_login_at' => 'datetime',
28            'password' => 'hashed',
29            'role' => UserRole::class,
30            'status' => Status::class,
31        ];
32    }
33
34    public function tenant(): BelongsTo { return $this->belongsTo(Tenant::class); }
35    public function store(): BelongsTo { return $this->belongsTo(Store::class); }
36    public function influencer(): HasOne { return $this->hasOne(Influencer::class); }
37
38    public function isAdmin(): bool
39    {
40        return in_array($this->role, [UserRole::Admin, UserRole::MainAdmin], true);
41    }
42
43    public function isMainAdmin(): bool
44    {
45        return $this->role === UserRole::MainAdmin;
46    }
47
48    public function isInfluencer(): bool
49    {
50        return $this->role === UserRole::Influencer;
51    }
52
53    public function isActive(): bool
54    {
55        return $this->status === Status::Active;
56    }
57}