Laravel Disable Created_at, Updated_at timestamps Example

Laravel Disable Created_at, Updated_at timestamps Example

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

Laravel Disable Created_at, Updated_at timestamps

There are two ways to disable created_at, updated_at timestamps using model and migration in laravel; as shown below:

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

To disable created_at and updated_at timestamps from Model

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

<?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 *