PHP code example of unusualdope / filament-model-translatable

1. Go to this page and download the library: Download unusualdope/filament-model-translatable 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/ */

    

unusualdope / filament-model-translatable example snippets


use Unusualdope\FilamentModelTranslatable\FmtPlugin;
use Filament\Panel;
 
class AdminPanelProvider extends PanelProvider
{
    public function panel(Panel $panel): Panel
    {
        return $panel
            // ...
            ->plugin(
                FmtPlugin::make()
            );
    }
}
 

use Unusualdope\FilamentModelTranslatable\Traits\HasTranslation;

class Post extends Model
{
    use HasTranslation;
}
    //...

protected string $lang_model = __CLASS__ . 'Language';

    /**
     * Translatable props needed
     */

    protected $lang_model = 'App\Models\PostTranslated'; //fqn of the translatable model 

    /**
     * Specify the foreign key if not the standard one
     */

    protected $lang_foreign_key = 'post_ext_id';  

    /**
     * Set to false in order to disable the translatable feature
     */

    protected bool $is_translatable = false;  

    use Filament\Forms\Components\Textarea;
    use Filament\Forms\Components\TextInput;
    
    public function setTranslatableFilamentFields()
    {
        return [
            TextInput::make('name')
                ->28)
                ->label('Meta Title'),
            Textarea::make('meta_description')
                ->maxLength(512)
                ->label('Meta Description'),
            //...
        ];
    }

    public static function form(Form $form): Form
    {
        return $form
            ->schema([
                //translatable
                FeatureGroup::addTranslatableFieldsToSchema('name'),
                //not translatable
                Forms\Components\TextInput::make('position')
                    ->

Unusualdope\FilamentModelTranslatable\Filament\Resources\Pages\FmtCreateRecord

class CreatePost extends FmtCreateRecord
{
    //..
}

Unusualdope\FilamentModelTranslatable\Filament\Resources\Pages\FmtEditRecord

class EditPost extends FmtEditRecord
{
    //..
}

$post = Post::find(1);
$post->currentLanguage->name;

$post = Post::find(1);
$post->languageData;