Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
25.00% |
2 / 8 |
|
50.00% |
2 / 4 |
CRAP | |
0.00% |
0 / 1 |
| User | |
25.00% |
2 / 8 |
|
50.00% |
2 / 4 |
10.75 | |
0.00% |
0 / 1 |
| auditName | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| auditOnly | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| store | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
| branch | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Models; |
| 4 | |
| 5 | // use Illuminate\Contracts\Auth\MustVerifyEmail; |
| 6 | use App\Support\Auditable; |
| 7 | use Illuminate\Database\Eloquent\Factories\HasFactory; |
| 8 | use Illuminate\Foundation\Auth\User as Authenticatable; |
| 9 | use Illuminate\Notifications\Notifiable; |
| 10 | use Illuminate\Support\Facades\Hash; |
| 11 | use Laravel\Sanctum\HasApiTokens; |
| 12 | use Spatie\Permission\Traits\HasRoles; |
| 13 | |
| 14 | class User extends Authenticatable |
| 15 | { |
| 16 | use Auditable, HasApiTokens, HasFactory, HasRoles, Notifiable; |
| 17 | |
| 18 | protected function auditName(): string |
| 19 | { |
| 20 | return 'staff'; |
| 21 | } |
| 22 | |
| 23 | protected function auditOnly(): array |
| 24 | { |
| 25 | return ['name', 'email', 'status', 'role']; |
| 26 | } |
| 27 | |
| 28 | /** |
| 29 | * The attributes that are mass assignable. |
| 30 | * |
| 31 | * @var array<int, string> |
| 32 | */ |
| 33 | protected $fillable = [ |
| 34 | 'name', |
| 35 | 'email', |
| 36 | 'status', |
| 37 | 'role', |
| 38 | 'branch_id', |
| 39 | 'locale', |
| 40 | 'password', |
| 41 | ]; |
| 42 | |
| 43 | /** |
| 44 | * The attributes that should be hidden for serialization. |
| 45 | * |
| 46 | * @var array<int, string> |
| 47 | */ |
| 48 | protected $hidden = [ |
| 49 | 'password', |
| 50 | 'remember_token', |
| 51 | ]; |
| 52 | |
| 53 | /** |
| 54 | * The attributes that should be cast. |
| 55 | * |
| 56 | * @var array<string, string> |
| 57 | */ |
| 58 | protected $casts = [ |
| 59 | 'email_verified_at' => 'datetime', |
| 60 | ]; |
| 61 | |
| 62 | public static function store($userData) |
| 63 | { |
| 64 | return self::query()->create([ |
| 65 | 'name' => $userData['name'], |
| 66 | 'email' => $userData['email'], |
| 67 | 'password' => Hash::make($userData['password']), |
| 68 | ]); |
| 69 | } |
| 70 | |
| 71 | public function branch() |
| 72 | { |
| 73 | return $this->belongsTo(Branch::class); |
| 74 | } |
| 75 | } |