覆盖默认时间戳名称在Lumen 7中不起作用

问题描述 投票:1回答:1

我已在模型中完成此操作...

const CREATED_AT = 'creation_date';
const UPDATED_AT = 'last_update';

并且不起作用。

在迁移文件中,我已完成...

$table->timestamps();
laravel database-migration lumen
1个回答
0
投票
/**
 * Add nullable creation and update timestamps to the table.
 *
 * @param  int  $precision
 * @return void
 */
public function timestamps($precision = 0)
{
    $this->timestamp('created_at', $precision)->nullable();

    $this->timestamp('updated_at', $precision)->nullable();
}

这是timestamps方法中的Illuminate\Database\Schema\Blueprint方法。覆盖CREATED_ATUPDATED_AT与之无关。它将在表中创建created_atupdated_at列。

您可以使用timestamp,例如$table->timestamp(MYMODEL:: CREATED_AT);

/**
 * Create a new timestamp column on the table.
 *
 * @param  string  $column
 * @param  int  $precision
 * @return \Illuminate\Database\Schema\ColumnDefinition
 */
public function timestamp($column, $precision = 0)
{
    return $this->addColumn('timestamp', $column, compact('precision'));
}
© www.soinside.com 2019 - 2024. All rights reserved.