👁 查看:StaticPage.php
路径:/home/boguraj1/public_html/epaper/app/Models/StaticPage.php
大小:571 B · 修改:2026-07-17 23:32:02 · 权限:0644 · 可写
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Str;

class StaticPage extends Model
{
    protected $fillable = ['title', 'slug', 'content', 'is_active'];

    protected $casts = ['is_active' => 'boolean'];

    protected static function booted()
    {
        static::saving(function ($page) {
            if (empty($page->slug)) {
                $page->slug = Str::slug($page->title);
            }
        });
    }

    public function getUrlAttribute(): string
    {
        return url('/page/' . $this->slug);
    }
}