2016-02-22 46 views
0

我想了解如何設置通過laravel連接到mysql數據庫連接的每個連接的時間戳是否有任何配置可以幫助實現此目的。Laravel:設置數據庫連接的時間戳laravel mysql

+0

只要你創建的表遷移加$表 - >時間戳();在你的遷移文件中的每個表格功能它將在你的表中添加created_at和updated_at兩列。 –

回答

0

無論何時更新模型,Eloquent都會自動更新updated_at屬性。只需將時間戳添加到您的遷移,就像這樣:然後

$table->timestamps(); 

created_atupdated_at字段將被添加到您的表和雄辯會自動使用它們。

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'); 
    } 
}