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 prevent Eloquent from adding created_at or updated_at timestamps?

What is the difference between empty(), isset(), != null, is_null() in PHP

How to check if a object has a static variable defined?

How to remove .php from the end of URLs with .htaccess

How to Extract Query String (from a URL) Into an Associative Array in PHP

How to check if a relation was loaded on an Eloquent model already?

What is camel case?

How to review blog posts (written by other users) before they get published on your WordPress blog?

How to autoload helper files with composer?

How to check if a user is logged in, inside a blade file?