generated from boboko/starter
34 lines
1.0 KiB
PHP
34 lines
1.0 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Services\Stoic;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use JacobJoergensen\LaravelPaper\Attributes\ContentPath;
|
|
use JacobJoergensen\LaravelPaper\Attributes\Driver;
|
|
use JacobJoergensen\LaravelPaper\Attributes\Timestamps;
|
|
use JacobJoergensen\LaravelPaper\Paper;
|
|
|
|
// 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.
|
|
#[Driver("markdown")]
|
|
#[ContentPath("resources/stoic/content/el/pages")]
|
|
#[Timestamps]
|
|
class StoicPage extends Model
|
|
{
|
|
use Paper;
|
|
|
|
/**
|
|
* 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"));
|
|
}
|
|
}
|