*/ use HasFactory; protected function casts(): array { return [ 'show_author' => 'boolean', 'show_story_points' => 'boolean', ]; } protected static function booted(): void { static::deleting(function (self $project): void { $project->permissionAssignments()->delete(); }); } protected function key(): Attribute { return Attribute::make( set: fn (string $value): string => Str::upper(trim($value)), ); } public function permissionAssignments(): MorphMany { return $this->morphMany(PermissionAssignment::class, 'scope'); } public function projectTemplate(): BelongsTo { return $this->belongsTo(ProjectTemplate::class, 'project_template_id'); } public function baseTemplate(): HasOne { return $this->hasOne(ProjectTemplate::class) ->where('is_published', false); } public function boardColumns(): HasMany { return $this->hasMany( BoardColumn::class, $this->project_template_id === null ? 'project_id' : 'project_template_id', $this->project_template_id === null ? 'id' : 'project_template_id', ) ->orderBy('position'); } public function ticketFieldDefinitions(): HasMany { return $this->hasMany( TicketFieldDefinition::class, $this->project_template_id === null ? 'project_id' : 'project_template_id', $this->project_template_id === null ? 'id' : 'project_template_id', ) ->orderBy('position'); } public function ticketPriorities(): HasMany { return $this->hasMany( TicketPriority::class, $this->project_template_id === null ? 'project_id' : 'project_template_id', $this->project_template_id === null ? 'id' : 'project_template_id', ) ->orderBy('position'); } public function ticketLinkTypes(): HasMany { return $this->hasMany( TicketLinkType::class, $this->project_template_id === null ? 'project_id' : 'project_template_id', $this->project_template_id === null ? 'id' : 'project_template_id', ) ->orderBy('position'); } public function ticketStatuses(): HasMany { return $this->hasMany( TicketStatus::class, $this->project_template_id === null ? 'project_id' : 'project_template_id', $this->project_template_id === null ? 'id' : 'project_template_id', ) ->orderBy('board_column_id') ->orderBy('position'); } public function ticketTypes(): HasMany { return $this->hasMany( TicketType::class, $this->project_template_id === null ? 'project_id' : 'project_template_id', $this->project_template_id === null ? 'id' : 'project_template_id', ) ->orderBy('position'); } public function repositoryConnections(): HasMany { return $this->hasMany( RepositoryConnection::class, $this->project_template_id === null ? 'project_id' : 'project_template_id', $this->project_template_id === null ? 'id' : 'project_template_id', ) ->orderBy('provider') ->orderBy('repository_full_name'); } public function notificationActions(): HasMany { return $this->hasMany( NotificationAction::class, $this->project_template_id === null ? 'project_id' : 'project_template_id', $this->project_template_id === null ? 'id' : 'project_template_id', ) ->orderBy('name') ->orderBy('id'); } public function tickets(): HasMany { return $this->hasMany(Ticket::class) ->orderByDesc('sequence_number'); } }