Laravel developers ditch separate tables for JSON-based translations

Laravel Daily////2 min read

Multilingual Architecture via JSON Fields

Managing 10 or more languages in a modern web application requires a shift away from cumbersome relational tables toward flexible JSON structures. Using the spatie/laravel-translatable package allows Laravel developers to store multiple language values within a single database column. This approach eliminates the need for complex joins or secondary translation tables, which can significantly clutter a schema as the application scales.

Global Middleware and Localized Routing

To ensure a seamless user experience, the application uses a custom SetLocale middleware. This logic extracts the language code directly from the URL prefix—such as /es/ for Spanish—and sets the application state accordingly. By validating these prefixes against a regex pattern, the system maintains SEO integrity while ensuring that every route remains strictly localized. Additionally, the middleware persists the user's choice in a cookie, allowing for a consistent experience during return visits.

Dynamic UI via Filament Tabs

The Filament admin panel provides a highly visual way to manage these translations. Instead of a single massive form, the implementation uses dynamic tabs that loop through a locales configuration file. Each tab displays an emoji flag and a set of input fields.

foreach (config('locales') as $code => $locale) {
    $tabs[] = Tab::make($locale['name'])
        ->icon($locale['flag'])
        ->schema([
            TextInput::make("title.$code")
                ->required($code === 'en'),
            Textarea::make("description.$code"),
        ]);
}
Laravel developers ditch separate tables for JSON-based translations
Laravel Multi-Language Travel Website with Filament Panel

This structure ensures that only the primary language (English) requires validation, while others remain optional.

Performance Tradeoffs with Astrotomic

While JSON fields offer flexibility, high-traffic applications with heavy SQL querying might struggle with performance. In these scenarios, the astrotomic/laravel-translatable package serves as a robust alternative. Unlike Spatie's JSON approach, Astrotomic utilizes separate relational tables to store translations. This allows for faster indexing and more efficient sorting at the database level, though it increases the complexity of the initial database migration and model setup.

Topic DensityMention share of the most discussed topics · 7 mentions across 7 distinct topics
Filament
14%· products
Google Translate
14%· companies
Laravel
14%· products
SEO
14%· products
Other topics
29%
End of Article
Source video
Laravel developers ditch separate tables for JSON-based translations

Laravel Multi-Language Travel Website with Filament Panel

Watch

Laravel Daily // 9:47

Tutorials, and demo projects with Laravel framework. Host: Povilas Korop

Who and what they mention most
Laravel
41.1%23
Filament
19.6%11
PHP
14.3%8
Composer
12.5%7
2 min read0%
2 min read