PHP code example of kaantanis / filament-model-translatable

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

    

kaantanis / filament-model-translatable example snippets



return [
    // except default locale on your app.php
    'supported_locales' => [
        'tr',
        'de',
    ],

    'cache_time' => 10, // in minutes
];

// model
use KaanTanis\FilamentModelTranslatable\Traits\ModelTranslatable;

class Post extends Model
{
    use ModelTranslatable;

    protected $translatable = [
        'title',
        'body',
    ];
}

// Resource
TextInput::make('title')
    ->translatable() // It works magically via macro

// Get the value
$model->title // It will return the value of the app()->getLocale()
$model->getTranslation('title', 'tr') // It will return the value of the target locale

// if the given locale does not exist from database, it will return the title of the model itself

// This will all work
TextInput::make('title')
    ->nt field slatable()
    ->
bash
php artisan vendor:publish --tag="filament-model-translatable-migrations"
php artisan migrate
bash
php artisan vendor:publish --tag="filament-model-translatable-config"