<?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);
}
}