5

laravel关闭update_at和created_at,关闭timestamp

 8 months ago
source link: https://viencoding.com/article/321
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

laravel关闭update_at和created_at,关闭timestamp

2023-12-05 07:26:21   Laravel

用laravel的时候,默认是自动更新timestamp,有时候并不需要自动更新update_at和created_at,因此需要在model中关闭它

在模型中增加一个变量timestamps,并且赋值false,就可以关闭了

public $timestamps = false;

如果想改变timestamps格式可以修改:

protected $dateFormat='U';

如果想改变timestamps字段名字,可以修改:

const UPDATED_AT = 'updateAt';
const CREATED_AT = 'createAt';

viencoding.com版权所有,允许转载,但转载请注明出处和原文链接: https://viencoding.com/article/321 欢迎小伙伴们在下方评论区留言 ~ O(∩_∩)O
文章对我有帮助, 点此请博主吃包辣条 ~ O(∩_∩)O


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK