FilamentF
Filament10mo ago
holiq

spatie translatable on custom page

I have custom page for manage home page content like bellow, i want to make it support multilingual with filament-spatie-translatable without change it into resource, how to do it?

<?php

namespace App\Filament\Pages;

use App\Models\HomeContent;
use Filament\Actions\Action;
use Filament\Forms\Components\FileUpload;
use Filament\Forms\Components\Textarea;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Concerns\InteractsWithForms;
use Filament\Forms\Contracts\HasForms;
use Filament\Forms\Form;
use Filament\Notifications\Notification;
use Filament\Pages\Page;

class HomeContentPage extends Page implements HasForms
{
    use InteractsWithForms;

    protected static ?string $navigationIcon = 'heroicon-o-home-modern';

    protected static string $view = 'filament.pages.home-content';

    protected static ?string $title = 'Home Content';

    protected static ?string $navigationGroup = 'Settings';

    public ?array $data = [];

    public function mount(): void
    {
        $this->data = HomeContent::first()?->toArray();
        $this->form->fill($this->data);
    }

    public function form(Form $form): Form
    {
        return $form
            ->schema([
                TextInput::make('title')
                    ->required(),
                Textarea::make('description')
                    ->required(),
                FileUpload::make('background')
                    ->image()
                    ->required(),
            ])
            ->statePath('data');
    }

    ...
}


i have add the header action and trait but still doesnt work
use Filament\Actions\LocaleSwitcher;
use Filament\Resources\Concerns\Translatable;
...
class HomeContentPage extends Page implements HasForms
{
    use InteractsWithForms, Translatable;

    ....
    protected function getHeaderActions(): array
    {
        return [
            LocaleSwitcher::make(),
        ];
    }
}
Filament
Filament support for Spatie's Laravel Translatable package.
Was this page helpful?