時(shí)間戳

2018-02-24 15:52 更新

默認(rèn) Eloquent 會(huì)自動(dòng)維護(hù)數(shù)據(jù)庫表的 created_at 和 updated_at 字段。只要把這兩個(gè)「時(shí)間戳」字段加到數(shù)據(jù)庫表, Eloquent 就會(huì)處理剩下的工作。如果不想讓 Eloquent 自動(dòng)維護(hù)這些字段,把下面的屬性加到模型類里:

關(guān)閉自動(dòng)更新時(shí)間戳

class User extends Model {
    protected $table = 'users';
    public $timestamps = false;
}

自定義時(shí)間戳格式

如果想要自定義時(shí)間戳格式,可以在模型類里重寫 getDateFormat 方法:

class User extends Model {
    protected function getDateFormat()
    {
        return 'U';
    }
}
以上內(nèi)容是否對(duì)您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)