*/ use HasFactory, Notifiable, HasPermissions; // Tambahan: Gunakan HasPermissions use WebAuthnAuthentication; /** * The attributes that are mass assignable. * * @var list */ protected $fillable = [ 'name', 'email', 'password', 'role', // Kode existing Anda 'role_id', // Tambahan: ID untuk relasi tabel Role 'phone', ]; /** * 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', ]; } /** * Tambahan: Relasi ke tabel Roles * Setiap user memiliki satu Role. */ /** * Relasi role memakai nama roleModel agar tidak bertabrakan dengan kolom legacy `role`. */ public function roleModel(): BelongsTo { return $this->belongsTo(Role::class, 'role_id'); } public function hasAccess($module, $permission): bool { $role = $this->roleModel; if ($role?->slug === 'admin' || $this->getRawOriginal('role') === 'admin') { return true; } return $role?->permissions() ->where('module_slug', $module) ->where($permission, 1) ->exists() ?? false; } }