Files
hoshpoint-backend/app/Models/TemplateKey.php

54 lines
1.2 KiB
PHP

<?php
namespace App\Models;
use App\Enums\TemplateKeyType;
use Illuminate\Database\Eloquent\Attributes\Fillable;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
#[Fillable([
'template_id',
'key',
'label',
'type',
'shape_name',
'is_required',
'sort_order',
'description',
])]
class TemplateKey extends Model
{
/**
* @return BelongsTo<Template, $this>
*/
public function template(): BelongsTo
{
return $this->belongsTo(Template::class);
}
/**
* Strip any literal curly braces the admin may have copied from the pptx placeholder
* (e.g. "{Main Title}" -> "Main Title"), since braces are added automatically at match time.
*/
protected function key(): Attribute
{
return Attribute::make(
set: fn (string $value) => trim($value, "{} \t\n\r\0\x0B"),
);
}
/**
* @return array<string, string>
*/
protected function casts(): array
{
return [
'type' => TemplateKeyType::class,
'is_required' => 'boolean',
'sort_order' => 'integer',
];
}
}