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

301 Redirect a single URL in .htaccess to a new location

What is the max size, by default, of GET variables?

How to hide the server signature (hide Apache info) from HTTP headers with .htaccess

What are some ways you can log debug messages and data in JS?

How to sort an array in javascript?

How to add a name prefix to all routes in a group?

How to force SSL in Apache's .htaccess?

How to create random numbers in JS?

How can you check if a variable is alphanum (alphanumeric, letters and numbers only) in PHP?

How to convert a string to an array of it's characters in PHP?