Overriding default timestamp names aren't working in Lumen 7

Viewed 49

I have done this in model...

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

And it doesn't work.

In migration file I have done...

$table->timestamps();
1 Answers
/**
 * 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();
}

This is the timestamps method inside Illuminate\Database\Schema\Blueprint method. Overriding CREATED_AT or UPDATED_AT has nothing to do with that. It will create created_at and updated_at column in your table.

You may use timestamp such as $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'));
}
Related