我正在使用https://github.com/Astrotomic/laravel-translatable使我的模型可翻译。
虽然我正在尝试使用以下方法更新模型以更新模式及其相关的翻译内容。
$product = $this->repository->update($input, $uuid);
// output of dd($input);
"uuid" => "44b26fb0-04b9-11eb-981a-6b01570d58ed"
"_method" => "PUT"
"en-us" => array:5 [▶]
"ar-eg" => array:5 [▶]
"account_uuid" => "a1c23ce0-04b7-11eb-b060-7faa78f23afd"
"type" => "tour"
"iso_4217" => "EGP"
"status" => "pending"
我收到了这个错误:
Column not found: 1054 Unknown column 'id' in 'where clause'
考虑到模型主键是“uuid”而不是“id”,因此外键是“product_uuid”而不是“product_id”,如下面的模型设置。
class Product extends Model implements Transformable, TranslatableContract
{
public $incrementing = false;
public $keyType = 'string';
public $timestamps = true;
protected $primaryKey = 'uuid';
public $translatedAttributes = [
'name',
'quantity_label_snigular',
'quantity_label_plural',
'brief_description',
'long_description',
'terms',
'meta_keywords',
];
public $translationForeignKey = 'product_uuid';
public $localeKey = 'uuid';
public $useTranslationFallback = true;
}
我遵循了此链接https://docs.astrotomic.info/laravel-translatable/usage/forms#saving-the-request上的确切文档,尽管我无法追踪该错误。