*/ protected $fillable = [ 'name', 'email', 'password', 'slug', 'two_factor_type' ]; /** * The attributes that should be hidden for serialization. * * @var array */ protected $hidden = [ 'password', 'remember_token', ]; /** * The attributes that should be cast. * * @var array */ protected $casts = [ 'email_verified_at' => 'datetime', 'password' => 'hashed', 'two_factor_type' => TwoFactorType::class, ]; public function userDetail() { return $this->hasOne(UserDetail::class, 'user_id'); } public function departments_work() { return $this->belongsToMany(Department::class, 'workers_departments')->withPivot(['position']); } public function departments_teach() { return $this->belongsToMany(Department::class, 'teachers_departments')->withPivot(['teaching_position']); } public function divisions() { return $this->belongsToMany(Division::class, 'division_user')->withPivot(['administrativePosition']); } public function faculties() { return $this->belongsToMany(Faculty::class, 'workers_faculties')->withPivot(['position']); } // Отношение к отправленным приглашениям public function sentInvitations() { return $this->hasMany(AcceptedInvitation::class, 'sender_id'); } // Отношение к полученным приглашениям public function receivedInvitation() { return $this->hasOne(AcceptedInvitation::class, 'receiver_id'); } protected static function booted(): void { if (config('filament-shield.dashboard_user.enabled', false)) { FilamentShield::createRole(name: config('filament-shield.dashboard_user.name', 'dashboard_user')); static::created(function (User $user) { $user->assignRole(config('filament-shield.dashboard_user.name', 'dashboard_user')); }); static::deleting(function (User $user) { $user->assignRole(config('filament-shield.dashboard_user.name', 'dashboard_user')); }); } } public function canAccessPanel(Panel|\Filament\Panel $panel): bool { switch ($panel->getId()) { case "admin": return $this->hasRole(Utils::getSuperAdminName()); case "dashboard": return $this->hasRole(config('filament-shield.dashboard_user.name', 'dashboard_user')) || $this->hasRole(Utils::getSuperAdminName()) || $this->hasRole(config('filament-shield.invited_user.name', 'invited_user')); default: return false; } } }