Getting Started
This guide will walk you through the installation and initial setup of the Eloquent Translatable package.
Installation
Require the package using Composer.
bashcomposer require aaix/eloquent-translatablePublish the configuration file (optional).
bashphp artisan vendor:publish --provider="Aaix\EloquentTranslatable\EloquentTranslatableServiceProvider" --tag="eloquent-translatable-config"This will create a
config/eloquent-translatable.phpfile where you can set a global fallback locale.
Setup
1. Create the Translations Table
For each model you want to make translatable (e.g., Product), run the provided Artisan command. It will generate the necessary migration file.
bash
php artisan make:translation-table ProductThen, run the migration:
bash
php artisan migrate2. Prepare Your Model
Add the HasTranslations trait to your model and define which attributes are translatable in the $translatable array.
php
<?php
namespace App\Models;
use Aaix\EloquentTranslatable\Traits\HasTranslations;
use Illuminate\Database\Eloquent\Model;
class Product extends Model
{
use HasTranslations;
public array $translatable = ['name', 'description'];
}