*/ use HasFactory, Notifiable; protected $fillable = ['name', 'email', 'password', 'role']; protected $hidden = ['password', 'remember_token']; protected function casts(): array { return [ 'email_verified_at' => 'datetime', 'password' => 'hashed', 'role' => UserRole::class, ]; } public function isAdmin(): bool { return $this->role === UserRole::Admin; } public function isSectionManager(): bool { return $this->role === UserRole::SectionManager || $this->isAdmin(); } public function sections(): BelongsToMany { return $this->belongsToMany(Section::class, 'section_user') ->withPivot('role_in_section'); } public function sourcesAssignees(): BelongsToMany { return $this->belongsToMany(Source::class, 'source_user'); } public function isMemberOfSection(Section $section): bool { return $this->sections()->where('section_id', $section->id)->exists(); } public function isManagerOfSection(Section $section): bool { return $this->isAdmin() || $this->sections() ->where('section_id', $section->id) ->wherePivot('role_in_section', 'section_manager') ->exists(); } }