Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
36.36% |
4 / 11 |
|
25.00% |
1 / 4 |
CRAP | |
0.00% |
0 / 1 |
| User | |
36.36% |
4 / 11 |
|
25.00% |
1 / 4 |
15.28 | |
0.00% |
0 / 1 |
| casts | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
1 | |||
| jokes | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| votes | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getDisplayNameAttribute | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
12 | |||
| 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\Relations\HasMany; |
| 8 | use Illuminate\Database\Eloquent\SoftDeletes; |
| 9 | use Illuminate\Foundation\Auth\User as Authenticatable; |
| 10 | use Illuminate\Notifications\Notifiable; |
| 11 | use Laravel\Sanctum\HasApiTokens; |
| 12 | use Spatie\Permission\Traits\HasRoles; |
| 13 | |
| 14 | class User extends Authenticatable |
| 15 | { |
| 16 | /** @use HasFactory<\Database\Factories\UserFactory> */ |
| 17 | use HasFactory, Notifiable, HasApiTokens, HasRoles, SoftDeletes; |
| 18 | |
| 19 | /** |
| 20 | * The attributes that are mass assignable. |
| 21 | * |
| 22 | * @var list<string> |
| 23 | */ |
| 24 | protected $fillable = [ |
| 25 | 'name', |
| 26 | 'given_name', |
| 27 | 'family_name', |
| 28 | 'email', |
| 29 | 'password', |
| 30 | 'status', |
| 31 | ]; |
| 32 | |
| 33 | /** |
| 34 | * The attributes that should be hidden for serialization. |
| 35 | * |
| 36 | * @var list<string> |
| 37 | */ |
| 38 | protected $hidden = [ |
| 39 | 'password', |
| 40 | 'remember_token', |
| 41 | ]; |
| 42 | |
| 43 | /** |
| 44 | * Get the attributes that should be cast. |
| 45 | * |
| 46 | * @return array<string, string> |
| 47 | */ |
| 48 | protected function casts(): array |
| 49 | { |
| 50 | return [ |
| 51 | 'email_verified_at' => 'datetime', |
| 52 | 'password' => 'hashed', |
| 53 | ]; |
| 54 | } |
| 55 | |
| 56 | public function jokes(): HasMany |
| 57 | { |
| 58 | return $this->hasMany(Joke::class); |
| 59 | } |
| 60 | |
| 61 | public function votes(): HasMany |
| 62 | { |
| 63 | return $this->hasMany(Vote::class); |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * Get the user's display name (nickname/preferred name) |
| 68 | */ |
| 69 | public function getDisplayNameAttribute(): string |
| 70 | { |
| 71 | if ($this->name) { |
| 72 | return $this->name; |
| 73 | } |
| 74 | |
| 75 | if ($this->given_name) { |
| 76 | return $this->given_name; |
| 77 | } |
| 78 | |
| 79 | return $this->family_name ?? 'User'; |
| 80 | } |
| 81 | } |