Laravel Disable Created_at and Updated_at timestamps

Laravel Disable Created_at and Updated_at timestamps

Laravel disable created_at and updated_at timestamps; In this tutorial, you will learn how to disable created_at and updated_at timestamps in laravel.

Laravel Disable Created_at and Updated_at timestamps

There are two ways to disable created_at and updated_at timestamps in laravel; as shwon below:

  • To disable created_at and updated_at timestamps from Model
  • To disable created_at and updated_at timestamps from Migration

To disable created_at and updated_at timestamps from Model

You can declare public $timestamps = false; in your laravel model to disable timestamp:

<?php


namespace App;


use Illuminate\Database\Eloquent\Model;


class Item extends Model
{
    protected $fillable = ['title','content'];


    public $timestamps = false;
}

To disable created_at and updated_at timestamps from Migration

You can also disable timestamps by removing $table->timestamps() from your migration file; as shown below:

    public function up()
    {
        Schema::create('users', function (Blueprint $table) {
            $table->increments('id');
            $table->string('name');
            $table->string('email')->unique()->nullable();
            $table->string('provider');
            $table->string('provider_id');
            $table->timestamp('email_verified_at')->nullable();
            $table->string('password')->nullable();
            $table->rememberToken()->nullable();
            $table->timestamps(); // remove this line for disabling created_at and updated_at date
        });
    }

Recommended Laravel Tutorials

Recommended:-Laravel Try Catch

AuthorAdmin

My name is Devendra Dode. I am a full-stack developer, entrepreneur, and owner of Tutsmake.com. I like writing tutorials and tips that can help other developers. I share tutorials of PHP, Python, Javascript, JQuery, Laravel, Livewire, Codeigniter, Node JS, Express JS, Vue JS, Angular JS, React Js, MySQL, MongoDB, REST APIs, Windows, Xampp, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL and Bootstrap from a starting stage. As well as demo example.

Leave a Reply

Your email address will not be published. Required fields are marked *