How to prevent Eloquent from adding created_at or updated_at timestamps?

Laravel: How to prevent Eloquent from adding created_at or updated_at timestamps?

If you want to disable both created_at and updated_at then add this to your model:

  1. const UPDATED_AT = null;
  2. const CREATED_AT = null;

If you want to disable just one of those fields (i.e. turn off created_at but keep updated_at, or keep created_at but disable the updated_at field) then just add the one line as required.

Also remember to remove this from the migrations:

  1. $table->timestamps()

Note: There is also the DELETED_AT const, if you use SoftDeletes.

webdevetc profile pic
webdevetc

I am a 29 year old backend web developer from London, mostly focusing on PHP and Laravel lately. This (webdevetc.com) is my blog where I write about some web development topics (PHP, Laravel, Javascript, and some server stuff). contact me here.



More...


Comments and discussion about How to prevent Eloquent from adding created_at or updated_at timestamps?

Found this interesting? Maybe you want to read some more in this series?

Or see other topics in the Laravel language

Or see other languages/frameworks:
PHP Laravel Composer Apache CentOS and Linux Stuff WordPress General Webdev and Programming Stuff JavaScript
Or see random questions

How to set up custom error pages in .htaccess for your Apache server (ErrorDocument)

How to set custom HTTP headers in Apache (by editing .htaccess)

How to force gzip compression in Apache with .htaccess

How to Enable Directory Listings in Apache with .htaccess

How to get the type of a variable in JS?

How do Invokable Controllers work in Laravel?

How to use Anonymous classes in PHP 7?

Set PHP config Variables (like ini_set) with .htaccess

How could you include a custom function for every single time PHP runs?

How do you run a PHP script from the command line?