PHP code example of amzad / filament-translatable-group
1. Go to this page and download the library: Download amzad/filament-translatable-group library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
amzad / filament-translatable-group example snippets
use Amzad\FilamentTranslatableGroup\TranslatableGroup;
// Single Field — via macro
TextInput::make('title')
->translatableGroup();
// Multiple Fields — via component
TranslatableGroup::make()
->schema([
Forms\Components\TextInput::make('title'),
Forms\Components\Textarea::make('content'),
]);
use Amzad\FilamentTranslatableGroup\TranslatableGroup;
use Filament\Forms\Components\Field;
$customizeField = function (Field $component, string $locale) {
// ...
};
// Globally in boot method
TranslatableGroup::configureUsing(function (TranslatableGroup $component) use ($customizeField) {
$component->modifyFieldsUsing($customizeField);
});
// Single Field
TextInput::make('title')
->translatableGroup(modifyFieldsUsing: $customizeField);
// Multiple Fields
TranslatableGroup::make()
->modifyFieldsUsing($customizeField)
->schema([
Forms\Components\TextInput::make('title'),
Forms\Components\Textarea::make('content'),
]);
$localesFn = function () {
return ['ar', 'en'];
// Also with labels:
return [
'ar' => 'Arabic',
'en' => 'English',
];
};
// Single Field
TextInput::make('title')
->translatableGroup(locales: $localesFn);
// Multiple Fields
TranslatableGroup::make()
->locales($localesFn)
->schema([
Forms\Components\TextInput::make('title'),
Forms\Components\Textarea::make('content'),
]);