为什么Laravel提供默认时间戳? [英] Why Laravel provides default timestamps?

查看:69
本文介绍了为什么Laravel提供默认时间戳?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我们在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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆