I'm using Laravel 5.1. To make it simple, I have the following code
迁移:
Schema::create('sitemap_data', function (Blueprint $table) {
// Primary and foreign keys
$table->increments('id');
$table->string('postUrl');
// Database functions
$table->timestamps();
});
And this is the code somewhere else I'm using
$sitemapData = SitemapData::firstOrNew([
'postUrl' => $post
]);
$sitemapData->save();
现在,根据Laravel的文件
同样,UPDATED_AT时间戳将自动更新,因此无需手动设置其值
The updated_at value should be updated in the table. However, this is not happening.
它只在第一次插入时设置,但不在更新时设置.当我手动操作时,就像这样
$sitemapData = SitemapData::firstOrNew([
'postUrl' => $post
]);
$sitemapData->updated_at = Carbon::now();
$sitemapData->save();
它起作用了.然而,doctor 说这应该会自动发生,那么这里出了什么问题?
我已经在stackoverflow上搜索了一些网站来寻找这个问题,但是我找到了Laravel 3或4.1、4.2等的位置.
How would I do that correctly?