39 lines
1018 B
PHP
39 lines
1018 B
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
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'])]
|
|
class TicketLinkType extends Model
|
|
{
|
|
/** @use HasFactory<TicketLinkTypeFactory> */
|
|
use HasFactory;
|
|
|
|
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');
|
|
}
|
|
}
|