*/ use HasFactory; use HasUuids; /** * The attributes that should be cast. * * @var array */ protected $casts = [ 'name' => 'string', 'archived_at' => 'datetime', ]; /** * @return BelongsTo */ public function organization(): BelongsTo { return $this->belongsTo(Organization::class, 'organization_id'); } /** * @return HasMany */ public function projects(): HasMany { return $this->hasMany(Project::class, 'client_id'); } /** * @param Builder $builder * @return Builder */ public function scopeVisibleByEmployee(Builder $builder, User $user): Builder { return $builder->whereHas('projects', function (Builder $builder) use ($user): Builder { /** @var Builder $builder */ return $builder->visibleByEmployee($user); }); } /** * @return Attribute */ protected function isArchived(): Attribute { return Attribute::make( get: fn (mixed $value, array $attributes) => isset($attributes['archived_at']), ); } }