PHP code example of spatie / nova-translatable

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

    

spatie / nova-translatable example snippets


public function fields(Request $request)
{
    return [
        ID::make()->sortable(),

        Translatable::make([
            Text::make('title'),
            Trix::make('text'),
        ]),
    ];
}

// in any service provider

\Spatie\NovaTranslatable\Translatable::defaultLocales(['en', 'fr']);

public function fields(Request $request)
{
    return [
        ID::make()->sortable(),

        Translatable::make([
            Text::make('title'),
            Trix::make('text'),
        ]),
    ];
}

/**
 * The columns that should be searched.
 *
 * @var array
 */
public static $search = [
    'id', 'name->en', 'name->fr',
];

Translatable::make([
    Text::make('title'),
    Trix::make('text'),
])->locales(['de', 'es']),

Translatable::displayLocalizedNameByDefaultUsing(function(Field $field, string $locale) {
   return ucfirst($field->name) . " [{$locale}]";
})

Translatable::make([
    Text::make('title'),
    Trix::make('text'),
])->displayLocalizedNameUsing(function(Field $field, string $locale) {
   return ucfirst($field->name) . " --- {$locale}]";
}),

Translatable::make([
    Text::make('My title', 'title'),
    Trix::make('text'),
])->displayLocalizedNameUsing(function(Field $field, string $locale) {
   return ucfirst($field->name) . " [{$locale}]";
}),

Translatable::make([
    Text::make('My title', 'title'),
    Trix::make('text'),
])->rules([
        'title' => ['en' => '

Translatable::make([
    Text::make('My title', 'title'),
    Trix::make('text'),
])->rulesFor('title', 'en', '