polarpress-pagebuilder/app/Models/PageRevision.php
Helge-Mikael Nordgård b8acb478b0
Some checks are pending
linter / quality (push) Waiting to run
tests / ci (push) Waiting to run
PageBuilder models
2025-05-05 15:09:04 +02:00

56 lines
1.1 KiB
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Str;
use App\Models\Page;
use App\Models\User;
class PageRevision extends Model
{
use HasFactory;
protected $fillable = [
'page_id',
'user_id',
'uuid',
'version',
'content',
'title',
'slug',
'label',
'active'
];
protected $casts = [
'content' => 'array',
];
protected static function boot() {
parent::boot();
static::creating(function ($revision) {
$revision->uuid = (string) Str::uuid();
if (!$revision->version) {
$latestVersion = self::where('page_id', $revision->page_id)->max('version') ?? 0;
$revision->version = $latestVersion + 1;
}
});
}
public function getRouteKeyName(): string {
return 'uuid';
}
public function page() {
return $this->belongsTo(Page::class);
}
public function editor() {
return $this->belongsTo(User::class, 'user_id');
}
}