Custom page and spatie translatable

I searched spatie translatable plugin and they didn’t mention on how to use this plugin in custom pages. So I was wondering how can I use this plugin in custom pages.
4 Replies
Wael
Wael11mo ago
@Algorithm Did u find anyway to use it ?
ahmant
ahmant10mo ago
Hello all, I am using "Spatie Translatable" on my custom "Setting" page, you can take a look on my code and get some idea on how you can set your own, for your custom page. And I am verry sorry for sending all the code, and not a direct answer 🙈, but I really didn't know to answer it other than that. And if you have any question, I am ready to help. Settings Table Schema

- id
- section
- key
- value

- id
- section
- key
- value
Setting Model

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Spatie\Translatable\HasTranslations;

class Setting extends Model
{
use HasFactory, HasTranslations;

protected $translatable = ['value'];

protected $guarded = [];
}

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Spatie\Translatable\HasTranslations;

class Setting extends Model
{
use HasFactory, HasTranslations;

protected $translatable = ['value'];

protected $guarded = [];
}
SettingResource.php
<?php

namespace App\Filament\Resources;

use App\Filament\Resources\SettingResource\Pages;
use App\Models\Setting;
use Filament\Resources\Concerns\Translatable;
use Filament\Forms\Form;
use Filament\Resources\Resource;

class SettingResource extends Resource
{
use Translatable;

protected static ?string $model = Setting::class;

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

public static $sectionKeySeparator = '--';

public static function form(Form $form): Form
{
return $form->schema([]);
}

public static function getTranslatableAttributes(): array
{
$sectionKeySeparator = static::$sectionKeySeparator;
return [
"general{$sectionKeySeparator}website_name",
];
}

public static function getPages(): array
{
return [
'index' => Pages\Setting::route('/'),
];
}
}
<?php

namespace App\Filament\Resources;

use App\Filament\Resources\SettingResource\Pages;
use App\Models\Setting;
use Filament\Resources\Concerns\Translatable;
use Filament\Forms\Form;
use Filament\Resources\Resource;

class SettingResource extends Resource
{
use Translatable;

protected static ?string $model = Setting::class;

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

public static $sectionKeySeparator = '--';

public static function form(Form $form): Form
{
return $form->schema([]);
}

public static function getTranslatableAttributes(): array
{
$sectionKeySeparator = static::$sectionKeySeparator;
return [
"general{$sectionKeySeparator}website_name",
];
}

public static function getPages(): array
{
return [
'index' => Pages\Setting::route('/'),
];
}
}
ahmant
ahmant10mo ago
Setting custom page app\Filament\Resources\SettingResource\Pages\Setting.php
Wael
Wael10mo ago
@ahmant Thank u so much 🙌 but I don't have resource in my custom
Want results from more Discord servers?
Add your server