为什么Laravel提供默认时间戳? [英] Why Laravel provides default timestamps?
问题描述
当我们在Laravel中创建新的模型或数据库迁移时,我们可以使用 $ table-> timestamps();
来创建 created_at
和 updated_at 代码>默认情况下.为什么从最佳项目结构的角度来看,项目需要这些字段?
When we create a new Model or database migration in Laravel we can use $table->timestamps();
which creates created_at
and updated_at
by default. Why does a project required these fields in the view of a best project structure?
推荐答案
在表中插入的每个 Model/Records
最好跟踪其 created_at
时间和 updated_at
时间.时间戳
用例可能因个人而异.
Every Model/Records
you insert in table it`s better to track its created_at
time and updated_at
time. Timestamp
use cases could be different depending upon indiviusal.
大多数开发人员都使用timepstamp来跟踪其数据库记录.
Most developer use timepstamp to track their database records.
这就是为什么Laravel Eloquent默认提供 created_at
和 updated_at
选项的原因.每当创建模型/记录时,都会自动设置 created_at
列值,并且只要记录被更新时, updated_at
列值就会自动设置为该时间,因此开发人员需要编写最少的代码来管理时间戳
That`s why Laravel Eloquent by default provide created_at
and updated_at
options. Whenever Model/Records get created created_at
column value get set automatically and whenever record get updated updated_at
column value set to that time automatically, so developer need to write minimum code for managing timestamps.
Laravel时间戳是可选的,请在模型中使用 public $ timestamps = false;
禁用时间戳.
Laravel timestamps are optional use public $timestamps = false;
in Model to disable timestamp.
这篇关于为什么Laravel提供默认时间戳?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!