$timeEntries * @property-read bool $is_done * * @method static TaskFactory factory() */ class Task extends Model implements AuditableContract { use CustomAuditable; /** @use HasFactory */ use HasFactory; use HasUuids; /** * The attributes that should be cast. * * @var array */ protected $casts = [ 'name' => 'string', 'done_at' => 'datetime', ]; /** * @return BelongsTo */ public function project(): BelongsTo { return $this->belongsTo(Project::class); } /** * @return BelongsTo */ public function organization(): BelongsTo { return $this->belongsTo(Organization::class, 'organization_id'); } /** * @return HasMany */ public function timeEntries(): HasMany { return $this->hasMany(TimeEntry::class, 'task_id'); } /** * @param Builder $builder * @return Builder */ public function scopeVisibleByEmployee(Builder $builder, User $user): Builder { return $builder->whereHas('project', function (Builder $builder) use ($user): Builder { /** @var Builder $builder */ return $builder->visibleByEmployee($user); }); } /** * @return Attribute */ public function isDone(): Attribute { return Attribute::make( get: fn (mixed $value, array $attributes) => isset($attributes['done_at']), ); } }