projectxmatt projectxmatt - 3 months ago 19
PHP Question

Disable Laravel's Eloquent timestamps

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?

Answer

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.