禁用Laravel的雄辩时间戳 [英] Disable Laravel's Eloquent timestamps
问题描述
updated_at
/ created_at
字段添加到我们所有的表中一个记录类,为我们做了更深入的工作。 我知道我可以设置 $ timestamps = false;
:
Vendor \laravel\framework\src\illuminate\Datebase\Eloquent\Model.php
不过,我宁愿不要更改Laravel的核心文件,也可以让我的所有模特都在顶端。有没有办法在所有模型的其他地方禁用?
您必须声明 public $每个模型中的时间戳= false;
,或者创建一个BaseModel,在那里定义它,并让所有的模型都扩展它,而不是雄辩。只要不介意,如果您使用Eloquent,枢纽表必须有时间戳。
更新:请注意,在Laravel v3之后,数据透视表中不再需要时间戳。
I'm in the process of converting one of our web applications from CodeIgniter to Laravel. However at this moment we don't want to add the updated_at
/ created_at
fields to all of our tables as we have a logging class that does all this in more depth for us already.
I'm aware I can set $timestamps = false;
in:
Vendor\laravel\framework\src\illuminate\Datebase\Eloquent\Model.php
However I'd rather not change a core file for Laravel, or have everyone of my models have that at the top. Is there any way to disable this elsewhere for all models?
You either have to declare public $timestamps = false;
in every model, or create a BaseModel, define it there, and have all your models extend it instead of eloquent. Just bare in mind pivot tables MUST have timestamps if you're using Eloquent.
Update: Note that timestamps are no longer REQUIRED in pivot tables after Laravel v3.
这篇关于禁用Laravel的雄辩时间戳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!