Add multiple translation to translation table
SOLVED
Hi everyone, I've been working on a Laravel project and encountered a perplexing issue that I haven't been able to resolve, despite consulting with ChatGPT for assistance. I'm hoping someone here might be able to shed some light on it.
Problem:
I'm trying to add new translations to a translations table in my Laravel application. However, when I attempt to insert a new translation, I consistently receive the following error:
Illuminate\Database\QueryException
PHP 8.2.4
10.38.2
SQLSTATE[HY000]: General error: 1364 Field 'locale' doesn't have a default value
INSERT INTO
translations
(key
, updated_at
, created_at
) VALUES (123, 2023-12-30 20:01:10, 2023-12-30 20:01:10)
Expected Behavior:
My intention is for the system to insert one row per language into the database, all with the same key, but with different locale values.
Current Observation:
The locale value doesn't seem to be getting inserted, and I can't figure out why. This is leading to a failure due to the lack of a default value for the locale field.
Relevant Code Snippet:
Here's the Eloquent model for Translation:
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Translation extends Model
{
use HasFactory;
protected $fillable = [
'locale',
'key',
'value',
];
}
TranslationResource : https://pastebin.com/4wMKuvgZ4 Replies
Anyone with an idea? π
Your resource shows some logging commands. What's the output in the logs?
Also, when the QueryException is thrown, what line, and what file, is it occurring at?
hello i want to apply this what is package used?
or what is the idea ?
Sorry for being offline - Has had some family related manners
It doesnt log anything unfortunately. So it isnt being called which i excpect it would.
The exeption is thrown in App
β\β
Http
β\β
Middleware
β\β
LocaleMiddleware
β
:β19
handle
Line 19:
return $next($request);
class LocaleMiddleware
{
public function handle($request, Closure $next)
{
if (Session::has('applocale') && array_key_exists(Session::get('applocale'), config('languages'))) {
App::setLocale(Session::get('applocale'));
}
return $next($request);
}
}
For the Admin interface iΒ΄m using filament. No package is used besides that. The idea is to build an option for me to easily manage translations. I will write them to the database, anden create the JSON files based on that.