PHP code example of novius / laravel-nova-translatable

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

    

novius / laravel-nova-translatable example snippets


use Laravel\Nova\Resource;
use Novius\LaravelNovaTranslatable\Nova\Actions\Translate;

class Post extends Resource
{
    // If your model uses the SoftDelete trait
    // public static $with = ['translationsWithDeleted'];
    // Otherwise
    public static $with = ['translations'];

    public function availableLocales(): array
    {
        return ['fr' => 'Français', 'en' => 'English'];
    }

    public function fields(NovaRequest $request): array
    {
        return [
            Locale::make(),
            Translations::make(),
        ];
    }

    // Optional, if you want to have a bar to switch locale of the items displayed on the index, more accessible than the filters 
    // work with the filter LocaleFilter
    public function cards(NovaRequest $request): array
    {
        return [
            new Locales(),
        ];
    }

    public function filters(NovaRequest $request): array
    {
        return [
            new LocaleFilter(),
        ];
    }

    // Optional, if you want to implement custom translation on your model  
    public function translate(): void
    {
         $model = $this->model();
         $model->attribute_to_translate = 'Translation';
    }
sh
php artisan vendor:publish --provider="Novius\LaravelNovaTranslatable\LaravelNovaTranslatableServiceProvider" --tag="public"
bash
php artisan vendor:publish --provider="Novius\LaravelNovaTranslatable\LaravelNovaTranslatableServiceProvider" --tag="lang"