Relationship for a translations table -> How to save entry?

Hello guys! I have a filament form with 2 tabs, where the user can enter translatable details in German and English Issue: Currently the translations are not saved to the course_translations table. How can I save the English title in translations table to the locale "en" and the german one to the locale "de" ? This is what the form components look like:
Tab::make('English')
->schema([
TextInput::make('translations.en.course_title') <-- Here
->label('Course Title')
->required()
->placeholder('Course Title'),
]),
Tab::make('German')
->schema([
TextInput::make('translations.de.course_title') <-- Here
->label('Course Title')
->required()
->placeholder('Course Title'),
]),
Tab::make('English')
->schema([
TextInput::make('translations.en.course_title') <-- Here
->label('Course Title')
->required()
->placeholder('Course Title'),
]),
Tab::make('German')
->schema([
TextInput::make('translations.de.course_title') <-- Here
->label('Course Title')
->required()
->placeholder('Course Title'),
]),
My course translation model:
class CourseTranslation extends Model
{
protected $fillable = [
'course_id',
'locale',
'course_title',
'course_description',
'course_excerpt'
];

public function course(): BelongsTo
{
return $this->belongsTo(Course::class);
}
}
class CourseTranslation extends Model
{
protected $fillable = [
'course_id',
'locale',
'course_title',
'course_description',
'course_excerpt'
];

public function course(): BelongsTo
{
return $this->belongsTo(Course::class);
}
}
And inside the Course model I have:
public function translations(): HasMany
{
return $this->hasMany(CourseTranslation::class);
}
public function translations(): HasMany
{
return $this->hasMany(CourseTranslation::class);
}
What's the best approach to realize this?
0 Replies
No replies yetBe the first to reply to this messageJoin