*/ use HasFactory; use HasUuids; /** * The attributes that should be cast. * * @var array */ protected $casts = [ 'type' => GoalType::class, 'comparison' => GoalComparison::class, 'target_seconds' => 'int', 'period' => GoalPeriod::class, 'filters' => GoalFiltersDto::class, 'week_start' => Weekday::class, 'archived_at' => 'datetime', ]; /** * @return BelongsTo */ public function organization(): BelongsTo { return $this->belongsTo(Organization::class, 'organization_id'); } /** * The member whose time entries count towards the goal, null for goals that count every member. * * @return BelongsTo */ public function member(): BelongsTo { return $this->belongsTo(Member::class, 'member_id'); } public function isPersonalGoalOf(Member $member): bool { return $this->type === GoalType::Personal && $this->member_id === $member->getKey(); } /** * @return Attribute */ protected function isArchived(): Attribute { return Attribute::make( get: fn (mixed $value, array $attributes) => isset($attributes['archived_at']), ); } /** * @param Builder $builder * @return Builder */ public function scopeArchived(Builder $builder): Builder { return $builder->whereNotNull('archived_at'); } /** * @param Builder $builder * @return Builder */ public function scopeNotArchived(Builder $builder): Builder { return $builder->whereNull('archived_at'); } }