Laravel 13 + Filament 5 admin panel and REST API for a non-profit developer collective, backed by the Pireon OAuth identity server. The public site is a separate, server-rendered application consuming /api/public/v1. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
60 lines
1.5 KiB
PHP
60 lines
1.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Models\Concerns\BumpsContentVersion;
|
|
use App\Models\Concerns\HasRevisions;
|
|
use Database\Factories\CategoryFactory;
|
|
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
use Spatie\Translatable\HasTranslations;
|
|
|
|
/**
|
|
* @property array<string, string> $name
|
|
* @property array<string, string> $slug
|
|
*/
|
|
#[Fillable(['name', 'slug', 'description', 'color', 'position', 'is_visible'])]
|
|
class Category extends Model
|
|
{
|
|
/** @use HasFactory<CategoryFactory> */
|
|
use BumpsContentVersion, HasFactory, HasRevisions, HasTranslations, SoftDeletes;
|
|
|
|
/**
|
|
* Columns stored as a locale => value JSON map.
|
|
*
|
|
* @var array<int, string>
|
|
*/
|
|
public array $translatable = ['name', 'slug', 'description'];
|
|
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'is_visible' => 'boolean',
|
|
'position' => 'integer',
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @return HasMany<Page, $this>
|
|
*/
|
|
public function pages(): HasMany
|
|
{
|
|
return $this->hasMany(Page::class);
|
|
}
|
|
|
|
/**
|
|
* @param Builder<$this> $query
|
|
* @return Builder<$this>
|
|
*/
|
|
public function scopeVisible(Builder $query): Builder
|
|
{
|
|
return $query->where('is_visible', true);
|
|
}
|
|
}
|