Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message
Laravel Translatable Db

Laravel Translatable Db Laravel Package

flobbos/laravel-translatable-db

Store model translations in a dedicated database table with Laravel. flobbos/laravel-translatable-db adds a simple translatable trait, helpers, and query support so you can persist and retrieve localized fields cleanly without JSON columns.

View on GitHub
Deep Wiki
Context7

A Laravel package for multilingual models

Frequently asked questions about Laravel Translatable Db
How do I install flobbos/laravel-translatable-db in a Laravel 9+ project?
The package was last updated for Laravel 5.8, so you’ll need to fork it and manually update dependencies like Eloquent casts or service providers. Start by running `composer require flobbos/laravel-translatable-db` in your Laravel 5.8 project, then test compatibility before migrating. For Laravel 9+, consider alternatives like `spatie/laravel-translatable` or custom solutions.
Can this package handle dynamic translation keys (e.g., user-defined fields) or only predefined ones?
The package expects you to define translatable fields in the `$translatable` array on your model (e.g., `['title', 'description']`). Dynamic keys aren’t natively supported, so you’d need to extend the trait or use a workaround like JSON columns for variable attributes. Check the README for customization hooks.
What happens if a translation is missing for a requested locale? Does it fall back to a default?
The package doesn’t enforce fallback logic by default, but you can implement it in your model’s `getTranslation()` method or via accessors. For example, add logic to return a default locale’s value (e.g., `en`) if the requested locale (e.g., `fr`) is missing. Test edge cases like concurrent writes to avoid race conditions.
Will this work with PostgreSQL’s JSONB or MySQL’s JSON columns for translations?
No, this package stores translations in separate database tables (not JSON columns). If you’re using PostgreSQL JSONB or MySQL JSON, you’d need to either migrate data to the package’s schema or use a different solution like `spatie/laravel-translatable`. The package assumes relational tables for translations.
How do I migrate existing JSON-based translations (e.g., `title->en`, `title->fr`) to this package’s structure?
You’ll need a custom migration script to parse your JSON/array data and insert rows into the new `translations` table. Use Eloquent queries to loop through models, extract translations, and populate the package’s schema. Test with a backup first, as this is a manual process with no built-in tooling.
Does this package support Laravel’s API resources or serializers (e.g., Spatie’s Laravel Data) for translated responses?
Yes, you can use the package’s `translatable()` helper or accessors in your API resources. For example, add `$resource->append(['translations'])` or customize the `toArray()` method to include translated fields. Pair it with locale-aware request handling (e.g., `request()->header('Accept-Language')`) for dynamic responses.
Are there performance concerns with large datasets (e.g., thousands of translations per model)?
The package uses separate tables for translations, which can bloat your database if not optimized. For large datasets, consider indexing the `model_id` and `locale` columns, or batch queries to reduce overhead. Test with your expected scale—JSON columns might be simpler for read-heavy workloads.
How do I test translation logic in PHPUnit or Pest? Can I mock translations?
You can mock translations by overriding the `getTranslation()` method in your model’s tests or using partial mocks. For example, in Pest: `$model->shouldReceive('getTranslation')->andReturn(['title' => ['en' => 'Test']])`. Test edge cases like missing locales, concurrent writes, and fallback behavior. The package lacks built-in test utilities, so manual assertions are needed.
What are the alternatives to this package for Laravel multilingual models?
Consider `spatie/laravel-translatable` (more maintained, supports Laravel 9+), `knuckleswtf/laravel-translatable` (active development), or database-level solutions like PostgreSQL’s `jsonb` with custom queries. If you need NoSQL, evaluate MongoDB’s array storage or custom Eloquent models. Weigh trade-offs like schema complexity and query performance.
How do I handle concurrent writes to translations (e.g., two users editing the same field in different locales)?
The package doesn’t include built-in concurrency controls, so you’ll need to implement them manually. Use database transactions or optimistic locking (e.g., `lockForUpdate()`) when saving translations. For high-traffic apps, consider caching translated fields with a short TTL or using a queue for async updates.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
nasirkhan/laravel-sharekit
directorytree/privacy-filter-classifier
directorytree/privacy-filter
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
22h/doctrine-garbage-collection-bundle
agtp/agtp-php
agtp/mod-php
splash/sonata-admin
splash/metadata
splash/openapi
splash/scopes
splash/toolkit
testo/output-teamcity
testo/bridge-symfony