'boolean', 'sort_order' => 'integer' ]; public function scopeOrdered($query) { return $query->orderBy('sort_order')->orderBy('created_at'); } public function scopeActive($query) { return $query->where('is_active', true); } protected static function boot() { parent::boot(); static::creating(function ($page) { if (empty($page->slug)) { $page->slug = Str::slug($page->title); } if (is_null($page->sort_order)) { $page->sort_order = static::max('sort_order') + 1; } }); static::updating(function ($page) { if ($page->isDirty('title') && empty($page->slug)) { $page->slug = Str::slug($page->title); } }); } }