F
Filamentβ€’11mo ago
egmose5492dk

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/4wMKuvgZ
Pastebin
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
4 Replies
egmose5492dk
egmose5492dkOPβ€’11mo ago
Anyone with an idea? πŸ™‚
DrByte
DrByteβ€’11mo ago
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?
mohamedali5738
mohamedali5738β€’11mo ago
hello i want to apply this what is package used? or what is the idea ?
egmose5492dk
egmose5492dkOPβ€’11mo ago
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.
Want results from more Discord servers?
Add your server