Files
KanbanGit/app/Models/TicketLinkType.php
T

48 lines
1.3 KiB
PHP

<?php
namespace App\Models;
use App\Models\Concerns\SyncsProjectTemplateOwnership;
use Database\Factories\TicketLinkTypeFactory;
use Illuminate\Database\Eloquent\Attributes\Fillable;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
#[Fillable(['label', 'counterpart_label', 'position', 'project_id', 'project_template_id'])]
class TicketLinkType extends Model
{
/** @use HasFactory<TicketLinkTypeFactory> */
use HasFactory;
use SyncsProjectTemplateOwnership;
protected static function booted(): void
{
static::saving(function (self $ticketLinkType): void {
$ticketLinkType->syncProjectTemplateOwnership();
});
}
public function counterpartLabel(): string
{
return $this->counterpart_label ?: $this->label;
}
public function labelForSource(bool $isSourceTicket): string
{
return $isSourceTicket ? $this->label : $this->counterpartLabel();
}
public function project(): BelongsTo
{
return $this->belongsTo(Project::class);
}
public function ticketLinks(): HasMany
{
return $this->hasMany(TicketLink::class)
->orderBy('id');
}
}