*/ use BelongsToTenant, HasFactory, HasPublicIdentifier, HasRoles, Notifiable; protected $fillable = [ 'name', 'email', 'password', 'user_type', 'status', 'userable_type', 'userable_id', 'contractor_id', 'must_change_password', ]; protected $hidden = [ 'password', 'remember_token', ]; protected function casts(): array { return [ 'email_verified_at' => 'datetime', 'password' => 'hashed', 'must_change_password' => 'boolean', ]; } public function userable(): MorphTo { return $this->morphTo(); } public function employeeProfile() { return $this->hasOne(EmployeeProfile::class); } public function customerProfile() { return $this->hasOne(CustomerProfile::class); } public function contractor(): BelongsTo { return $this->belongsTo(\Modules\ContractorManagement\Models\Contractor::class); } public function isAdmin(): bool { return $this->user_type === 'admin'; } public function isPlatformAdmin(): bool { return is_null($this->contractor_id) && $this->isAdmin(); } public function isContractorAdmin(): bool { return ! is_null($this->contractor_id) && $this->hasRole('Contractor'); } public function isContractorUser(): bool { return ! is_null($this->contractor_id); } public function isEmployee(): bool { return in_array($this->user_type, ['admin', 'employee']); } public function isCustomer(): bool { return $this->user_type === 'customer'; } public function isActive(): bool { return $this->status === 'active'; } public function scopeActive($query) { return $query->where('status', 'active'); } public function scopeOfType($query, string $type) { return $query->where('user_type', $type); } }