PHP code example of ceedcv-maya / shared-translations-laravel

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

    

ceedcv-maya / shared-translations-laravel example snippets


use Maya\Translations\Migrations as TranslationMigrations;

$this->loadMigrationsFrom(TranslationMigrations::translations());

use Illuminate\Database\Eloquent\Relations\Relation;

Relation::enforceMorphMap(['panel_alert' => \App\Models\PanelAlert::class]);

use Maya\Translations\Concerns\HasTranslations;

class PanelAlert extends Model
{
    use HasTranslations;
    protected array $translatable = ['text', 'action_label'];
}

// Escritura (reemplaza todas las traducciones del campo)
$alert->syncTranslations('text', ['es' => 'Hola', 'va' => 'Hola']);

// Lectura con fallback
$alert->translate('text', 'va', 'es');

// Serialización para API / payload de notificación
$alert->translationsMap(); // { "text": { "es": "…", "va": "…" }, ... }