Files
3dealer/app/Models/StoicPage.php
T

34 lines
1.0 KiB
PHP
Raw Normal View History

2026-08-26 13:43:30 +03:00
<?php
namespace App\Models;
2026-09-28 18:16:43 +03:00
use App\Services\Stoic;
2026-08-26 13:43:30 +03:00
use Illuminate\Database\Eloquent\Model;
use JacobJoergensen\LaravelPaper\Attributes\ContentPath;
use JacobJoergensen\LaravelPaper\Attributes\Driver;
use JacobJoergensen\LaravelPaper\Attributes\Timestamps;
use JacobJoergensen\LaravelPaper\Paper;
2026-09-28 18:16:43 +03:00
// Points at the default locale (el), which Stoic writes every field to. Other
// locales hold only the translatable fields — use localized() to get a page
// with those layered on top for the current locale.
2026-08-26 13:43:30 +03:00
#[Driver("markdown")]
2026-09-28 18:16:43 +03:00
#[ContentPath("resources/stoic/content/el/pages")]
2026-08-26 13:43:30 +03:00
#[Timestamps]
class StoicPage extends Model
{
use Paper;
2026-09-28 18:16:43 +03:00
/**
* The page in the current locale: the default-locale entry, with the
* current locale's non-empty fields (and body) swapped in. Untranslated
* fields fall back to the default locale.
*/
public static function localized(string $slug): ?static
{
$page = static::firstWhere('slug', $slug);
return $page?->forceFill(Stoic::localeOverrides("pages/{$slug}.md"));
}
2026-08-26 13:43:30 +03:00
}