generated from boboko/starter
stoic multilingual
This commit is contained in:
@@ -2,16 +2,32 @@
|
||||
|
||||
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/pages")]
|
||||
#[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"));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user