47 lines
1.2 KiB
PHP
47 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Models\Concerns\SyncsProjectTemplateOwnership;
|
|
use Database\Factories\TicketFieldDefinitionFactory;
|
|
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(['field_type', 'label', 'position', 'project_id', 'project_template_id'])]
|
|
class TicketFieldDefinition extends Model
|
|
{
|
|
/**
|
|
* @var array<int, string>
|
|
*/
|
|
public const FIELD_TYPES = [
|
|
'user',
|
|
'number',
|
|
];
|
|
|
|
/** @use HasFactory<TicketFieldDefinitionFactory> */
|
|
use HasFactory;
|
|
|
|
use SyncsProjectTemplateOwnership;
|
|
|
|
protected static function booted(): void
|
|
{
|
|
static::saving(function (self $ticketFieldDefinition): void {
|
|
$ticketFieldDefinition->syncProjectTemplateOwnership();
|
|
});
|
|
}
|
|
|
|
public function project(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Project::class);
|
|
}
|
|
|
|
public function ticketFieldValues(): HasMany
|
|
{
|
|
return $this->hasMany(TicketFieldValue::class)
|
|
->orderBy('ticket_id');
|
|
}
|
|
}
|