$organizations * @property Collection $timeEntries * @property Member $membership * * @method HasMany ownedTeams() * @method static UserFactory factory() * @method static Builder query() * @method Builder belongsToOrganization(Organization $organization) * @method Builder active() */ class User extends Authenticatable implements AuditableContract, FilamentUser, MustVerifyEmail { use CustomAuditable; use HasApiTokens; /** @use HasFactory */ use HasFactory; use HasProfilePhoto; use HasTeams; use HasUuids; use Notifiable; use TwoFactorAuthenticatable; /** * The attributes that are mass assignable. * * @var array */ protected $fillable = [ 'name', 'email', 'password', ]; /** * The attributes that should be hidden for serialization. * * @var array */ protected $hidden = [ 'password', 'remember_token', 'two_factor_recovery_codes', 'two_factor_secret', ]; /** * The attributes that should be cast. * * @var array */ protected $casts = [ 'name' => 'string', 'email' => 'string', 'email_verified_at' => 'datetime', 'is_admin' => 'boolean', 'is_placeholder' => 'boolean', 'week_start' => Weekday::class, ]; /** * The model's default values for attributes. * * @var array */ protected $attributes = [ 'week_start' => Weekday::Monday, ]; /** * Get the URL to the user's profile photo. * * @return Attribute */ protected function profilePhotoUrl(): Attribute { return Attribute::get(function (): string { return $this->profile_photo_path ? Storage::disk($this->profilePhotoDisk())->url($this->profile_photo_path) : $this->defaultProfilePhotoUrl(); }); } public function canAccessPanel(Panel $panel): bool { return in_array($this->email, config('auth.super_admins', []), true) && $this->hasVerifiedEmail(); } public function canBeImpersonated(): bool { return $this->is_placeholder === false; } /** * @return BelongsToMany */ public function organizations(): BelongsToMany { return $this->belongsToMany(Organization::class, Member::class) ->withPivot([ 'id', 'role', 'billable_rate', ]) ->withTimestamps() ->as('membership'); } /** * @return HasMany */ public function timeEntries(): HasMany { return $this->hasMany(TimeEntry::class); } /** * @return BelongsTo */ public function currentOrganization(): BelongsTo { return $this->belongsTo(Organization::class, 'current_team_id'); } /** * @return HasMany */ public function projectMembers(): HasMany { return $this->hasMany(ProjectMember::class, 'user_id'); } /** * @param Builder $builder */ public function scopeActive(Builder $builder): void { $builder->where('is_placeholder', '=', false); } /** * @param Builder $builder * @return Builder */ public function scopeBelongsToOrganization(Builder $builder, Organization $organization): Builder { return $builder->where(function (Builder $builder) use ($organization): Builder { return $builder->whereHas('organizations', function (Builder $query) use ($organization): void { $query->whereKey($organization->getKey()); })->orWhereHas('ownedTeams', function (Builder $query) use ($organization): void { $query->whereKey($organization->getKey()); }); }); } }