74 lines
1.8 KiB
PHP
74 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
|
|
class AiStyle extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
protected static function booted(): void
|
|
{
|
|
static::creating(function (self $style): void {
|
|
if ((int) ($style->version ?? 0) < 1) {
|
|
$style->version = 1;
|
|
}
|
|
});
|
|
|
|
static::updating(function (self $style): void {
|
|
$versionedFields = [
|
|
'prompt_template',
|
|
'negative_prompt_template',
|
|
'provider',
|
|
'provider_model',
|
|
'metadata',
|
|
'is_premium',
|
|
'requires_source_image',
|
|
];
|
|
|
|
if ($style->isDirty($versionedFields)) {
|
|
$current = max(1, (int) ($style->getOriginal('version') ?? 1));
|
|
$requested = max(1, (int) ($style->version ?? 0));
|
|
$style->version = max($requested, $current + 1);
|
|
}
|
|
});
|
|
}
|
|
|
|
protected $fillable = [
|
|
'key',
|
|
'name',
|
|
'version',
|
|
'category',
|
|
'description',
|
|
'prompt_template',
|
|
'negative_prompt_template',
|
|
'provider',
|
|
'provider_model',
|
|
'requires_source_image',
|
|
'is_premium',
|
|
'is_active',
|
|
'sort',
|
|
'metadata',
|
|
];
|
|
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'requires_source_image' => 'boolean',
|
|
'is_premium' => 'boolean',
|
|
'is_active' => 'boolean',
|
|
'version' => 'integer',
|
|
'sort' => 'integer',
|
|
'metadata' => 'array',
|
|
];
|
|
}
|
|
|
|
public function editRequests(): HasMany
|
|
{
|
|
return $this->hasMany(AiEditRequest::class, 'style_id');
|
|
}
|
|
}
|