<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
roundly-consulting / translatable-for-laravel example snippets
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use RoundlyConsulting\Translatable\Concerns\HasTranslations;
use RoundlyConsulting\Translatable\Contracts\Translatable;
Schema::create('topics', function (Blueprint $table): void {
$table->id();
$table->translatable('name'); // a jsonb column
$table->timestamps();
});
final class Topic extends Model implements Translatable
{
use HasTranslations;
protected $fillable = ['name'];
/** @var list<string> */
public array $translatable = ['name'];
}
use RoundlyConsulting\Translatable\Facades\Translatable;
Translatable::usingLocale('en', fn (): string => $topic->name); // 'Investing'
$topic->setTranslations('name', Translatable::fromInput($request->input('name'))); // replaces the map with the form's locales
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.