Home > Net >  Astrotomic Translatable - pivot column - Laravel 9
Astrotomic Translatable - pivot column - Laravel 9

Time:01-30

I'm having trouble translating a pivot column.

I've been trying all day to add this translation but it still doesn't work.

I'm using the package: enter image description here

Also, when I manually add transactions to the database, it does not display it.

I will be very grateful for help with this translation.

CodePudding user response:

Okay, I fixed it like this, only I have to pass id instead of slugs.

class Offer extends Model implements TranslatableContract
{
...
    public function attributeValues(): HasMany
    {
        return $this->hasMany(AttributeOffer::class);
    }
}
class AttributeOffer extends Pivot implements TranslatableContract
{
...
    protected $translationForeignKey = 'attribute_offer_id';
...
}
private function updateAttributeValues($offer, $attributes)
  {
        foreach ($attributes as $id => $values) {
            $offer->attributeValues()->whereAttributeId($id)->first()->update($values);
        }
  }
  • Related