*/ use HasApiTokens, HasFactory, Notifiable; /** * The attributes that are mass assignable. * * @var list */ protected $fillable = [ 'email', 'password', 'role', 'is_banned', 'device_token', 'device_id', 'topic_subscribe', 'profile_picture', 'remember_token', ]; /** * The attributes that should be hidden for serialization. * * @var list */ protected $hidden = [ 'password', 'remember_token', ]; /** * Get the attributes that should be cast. * * @return array */ protected function casts(): array { return [ 'email_verified_at' => 'datetime', 'password' => 'hashed', ]; } public function teacher() { return $this->hasOne(Teacher::class, 'id_user'); } public function student() { return $this->hasOne(Student::class, 'id_user'); } /** * Nama tampilan: ambil dari relasi teacher/student, fallback ke email. */ public function getDisplayNameAttribute(): string { if ($this->relationLoaded('teacher') ? $this->teacher : $this->teacher()->first()) { return $this->teacher->name; } if ($this->relationLoaded('student') ? $this->student : $this->student()->first()) { return $this->student->name; } return $this->email ?? 'Pengguna'; } /** * Label role dalam Bahasa Indonesia. */ public function getRoleLabelAttribute(): string { return match ($this->role) { 'admin' => 'Admin', 'teacher' => 'Guru', 'student' => 'Siswa', default => ucfirst((string) $this->role), }; } }