PHP code example of aenzenith / laravel-localizable

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

    

aenzenith / laravel-localizable example snippets


'locales' => [
    'en' => 'English',
    'fr' => 'French',
    /* */
    'es' => 'Spanish',
    'de' => 'German',
],

use Aenzenith\LaravelLocalizable\Localizable;

class Content extends Model
{
    use HasFactory, Localizable;

    protected $localizable = [
        'title',
        'content',
    ];

    /* ... */
}


    $localizables = Content::getLocalizables();

    //you can pass also locales list with config('localizable.locales') for language names

    return view('content.create', compact('localizables'));

    return Inertia::render('Content/Create', [
        'localizables' => Content::getLocalizables(),
    ]);

    $content = new Content();
    $content->save();

    $content->localize('en', 'title', 'English Title');
    $content->localize('en', 'content', 'English Content');

    $content->localize('fr', 'title', 'French Title');
    $content->localize('fr', 'content', 'French Content');

    $content->localizeMany(
        'en',
        [
            'title' => 'English Title',
            'content' => 'English Content'
        ]
    );

    $content->localizeMany(
        'fr',
        [
            'title' => 'French Title',
            'content' => 'French Content'
        ]
    );

    $content->localizeManyLocales(
        [
            'en' => [
                'title' => 'English Title',
                'content' => 'English Content'
            ],
            'fr' => [
                'title' => 'French Title',
                'content' => 'French Content'
            ]
        ]
    );

    $content->localizeManyLocales($request->localizations);

    $content = Content::first()->getLocalizations();
    /* or */
    $content = Content::first();
    $content->getLocalizations();

    $content->localizeManyLocales($request->localizations);

    app()->setLocale('fr');

    'field_fallback' => true,

    'field_fallback_value' => 'This field is not localized yet.',
bash
php artisan migrate

php artisan vendor:publish --provider="Aenzenith\LaravelLocalizable\LocalizableServiceProvider"