如何在可翻译字段中插入?

时间:2018-10-25 09:28:12

标签: php laravel eloquent laravel-5.1 lumen

使用Lumen 5.1,我想知道如何对可翻译字段进行CRUD,在我的情况下是name

这是迁移文件

class CreateDomainHolidays extends Migration
{

    protected $table = 'domain_holidays';
    protected $app_table = true;

    public function up()

    {
        Schema::create($this->getTable(), function (Blueprint $table) {
            $table->increments('id');

            $table->integer('domain_id')->unsigned()->nullable();
            $table->foreign('domain_id')->references('id')
                ->on(self::getTableName('domains'))->onDelete('cascade');
            $table->string('name')->nullable()->default('')->translatable = true;
            $table->dateTime('start_date');
            $table->dateTime('end_date');
            $table->tinyInteger('half_day_start')->default(0);
            $table->tinyInteger('half_day_end')->default(0);
            $this->parenttable = $table;

        });
        $this->createTableWithTranslation($this->parenttable);

    }

    public function down()
    {
        $this->dropTranslationTable($this->getTable());
        Schema::drop($this->getTable());
    }
}

这是我的模特

 class Holiday extends BaseModel
    {
        protected $table = 'domain_holidays';
        protected $app_table = true;
        public $timestamps = false;

        protected $translation = true;
        public function translations()
        {
            return $this->hasMany('App\Models\General\HolidayTranslations', 'parent_id');
        }

    }

    class HolidayTranslations extends BaseTranslationModel
    {
        protected $table = 'domain_holidays_i18n';
        protected $primaryKey = 'translation_id';
    }
}

domain_holidays包含

id
domain_id
start_date
end_date
half_day_start
half_day_end

domain_holidays_i18n包含

translation_id
parent_id
lang
name

类似的东西不起作用

public static function setHoliday($domainId, $name, $startDate, $endDate, $halfDayStart, $halfDayEnd)
{
    Holiday::unguard();
    return Holiday::create([
        'domain_id' => $domainId,
        'name' => $name,
        'start_date' => $startDate,
        'end_date' => $endDate,
        'half_day_start' => $halfDayStart,
        'half_day_end' => $halfDayEnd
    ]);
}

邮递员会返回错误

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'name' in 'field list'

0 个答案:

没有答案