Laravel 5 Laravel:在数据库连接Laravel mysql上设置时间戳

Laravel 5 Laravel:在数据库连接Laravel mysql上设置时间戳,laravel-5,Laravel 5,我想了解如何通过laravel设置mysql数据库连接的每个连接的时间戳。是否有任何配置有助于实现这一点。Eloquent在更新模型时自动更新updated_at属性。只需将时间戳添加到迁移中,如下所示: $table->timestamps(); created_at和updated_at字段将被添加到您的表中,并且eloquent将自动使用它们 : 每当创建表迁移时,添加$table->timestamps();在迁移文件中的每个tables up函数中,它将在相应表的两列中添加cr

我想了解如何通过laravel设置mysql数据库连接的每个连接的时间戳。是否有任何配置有助于实现这一点。

Eloquent在更新模型时自动更新
updated_at
属性。只需将时间戳添加到迁移中,如下所示:

$table->timestamps();
created_at
updated_at
字段将被添加到您的表中,并且eloquent将自动使用它们

:


每当创建表迁移时,添加$table->timestamps();在迁移文件中的每个tables up函数中,它将在相应表的两列中添加created_和updated_。
<?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');
    }
}