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\Models\FmtModel;

class Post extends FmtModel
{
    //...

    /**
     * Translatable props needed
     */

    protected $lang_model = 'App\Models\PostLanguage'; //fqn of the translatable model 
    protected $lang_foreign_key = 'post_id'; //foreign key

    protected $is_translatable = true;
    protected $translatable = [
        'title' => [ //field name that will match with the LangModel db field and property
            'formType' => 'TextInput', //The type of form input field as in Filament
            'name' => 'Title', //Field Label
            'methods' => [ //The methods you want to call from filament on your field to define it
                '

self::addTranslatableFieldsToSchema(array $schema, Form $form, Bool false);

class PostResource extends Resource
{
    use FmtModelTrait;

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

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

    public static function form(Form $form): Form
    {

        $schema = [
            Forms\Components\Select::make('user_id')
                ->relationship('user', 'name')
                ->searchable()
                ->

Unusualdope\FilamentModelTranslatable\Filament\Resources\Pages\FmtCreateRecord

Unusualdope\FilamentModelTranslatable\Filament\Resources\Pages\FmtEditRecord

use Unusualdope\FilamentModelTranslatable\Filament\Resources\Pages\FmtCreateRecord;

class CreatePlan extends FmtCreateRecord
{
    protected static string $resource = PlanResource::class;
}