我想了解如何通过laravel设置与mysql数据库连接的每个连接的时间戳是否有任何配置有助于实现此目的。
答案 0 :(得分:0)
每当模型更新时,Eloquent都会自动更新updated_at
属性。只需为迁移添加时间戳,如下所示:
$table->timestamps();
然后会将 created_at
和updated_at
字段添加到您的表中,并且eloquent将自动使用它们。
Full example from the laravel docs:
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateFlightsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('flights', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('airline');
$table->timestamps(); // <<< Adds created_at and updated_at
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('flights');
}
}