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

AuthorDevendra Dode

Greetings, I'm Devendra Dode, a full-stack developer, entrepreneur, and the proud owner of Tutsmake.com. My passion lies in crafting informative tutorials and offering valuable tips to assist fellow developers on their coding journey. Within my content, I cover a spectrum of technologies, including 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. Whether you're starting out or looking for advanced examples, I provide step-by-step guides and practical demonstrations to make your learning experience seamless. Let's explore the diverse realms of coding together.

Leave a Reply

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