PHP code example of ildaviz / filament-language-tab
1. Go to this page and download the library: Download ildaviz/filament-language-tab 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/ */
ildaviz / filament-language-tab example snippets
namespace App\Models;
use Spatie\Translatable\HasTranslations;
class Posts extends Model
{
...
use HasTranslations;
public $translatable = [
'title',
'content',
'slug',
'images',
...
];
...
}
use FilamentLanguageTab\Concerns\UseTranslatablePage;
class CreatePost ...
{
use UseTranslatablePage;
...
use FilamentLanguageTab\Concerns\UseTranslatablePage;
class EditPost ...
{
use UseTranslatablePage;
...
public function setTranslatableLocales(): array
{
return [
'en',
'es',
'fr',
];
}
public function setTranslatableAttributes(): array
{
return [
'title',
'content',
'slug',
'images',
];
}
use FilamentLanguageTab\Components\TabsTranslatable;
use FilamentLanguageTab\Facades\LanguageTab;
TabsTranslatable::make('translations')
->makeForm(
// Use the "lang" props to have the language cycled
// You can also use the other Filament closures.
getLabelTab: function ($lang) {
return 'Translations ' . $lang;
},
// Use the "lang" props to have the language cycled
// You can also use the other Filament closures.
getFormTranslatableContent: function ($lang) {
return [
Forms\Components\Group::make([
Forms\Components\TextInput::make(LanguageTab::makeName('title', $lang))
->label(__(LanguageTab::makeName('title', $lang)))
->placeholder(__(LanguageTab::makeName('placeholder', $lang)))
-> ->
->languages(['en', 'es', 'fr'])
->makeForm(
// Use the "lang" props to have the language cycled
// You can also use the other Filament closures.
getLabelTab: function (string $lang) {}
// Use the "lang" props to have the language cycled
// You can also use the other Filament closures.
getFormTranslatableContent: function (string $lang) {}
)
LanguageTab::makeName('{name of field}', $lang)
//example:
LanguageTab::makeName('title', $lang)
//result:
'title-en'
// Use LanguageTab facade.
use FilamentLanguageTab\Facades\LanguageTab;
// Initialize the LanguageTab facade.
init()
// For change locales (optional)
setTranslatableLocales(array $locales = [])
// Set the translatable attributes from the specific model.
getTranslatableAttributes(string $modelClass)
// Set the translatable attributes. (optional)
setTranslatableAttributes(array $translatableAttributes = [])
// Use before create event
beforeCreate(string $modelClass, array $data)
// Use before fill event
beforeFill(Model $model, array $data)
// Use before save event
beforeSave(Model $model, array $data)
// Get the locales from the configuration.
array getLocales()
// Make the name of the field for the form.
string makeName(string $name, string $locale)
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.