ItSolutionStuff.com

Laravel Model Disable created_at and updated_at Update Record

By Hardik Savani • April 16, 2024
Laravel

As we know, we create new record in table using model then created_at and updated_at column value automatic set current timestamps. But sometime you require to prevent set timestamp of created_at and updated_at column, Maybe you don't have. So in this post we will learn how to make disabled timestamps value from model in laravel 6, laravel 7, laravel 8, laravel 9, laravel 10 and laravel 11 project too.

So, there are two way to create disable created_at and updated_at timestamps in laravel 5 application. So first you can simply "$timestamps" equals to false in your model. So you can do it as simple bellow example of Item model.

app/Models/CouponCode.php

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;

use Illuminate\Database\Eloquent\Model;

class CouponCode extends Model

{

use HasFactory;

protected $table = 'coupon_codes';

public $timestamps = false;

/**

* Write code on Method

*

* @return response()

*/

protected $fillable = [

'code',

'duration_type',

'duration',

'status'

];

}

I hope it can help you...

Tags: Laravel
Hardik Savani

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

📺 Subscribe on YouTube

We Are Recommending You

Laravel 10 Model Events Example Tutorial

Read Now →

How to Add Custom Attribute in Laravel Model?

Read Now →

Laravel Model Disable Primary Key & Auto Increment Example

Read Now →

Get Array of Ids from Eloquent Models in Laravel

Read Now →

How to Set Default Value in Laravel Model?

Read Now →

How to Select Specific Columns in Laravel Eloquent Model?

Read Now →

How to Get All Models in Laravel?

Read Now →

Laravel Model Caching - Performance Boost Tutorial

Read Now →

How to Call Model Function from Another Model in Codeigniter?

Read Now →

Laravel Improve Speed Performance using Model Caching Tutorial

Read Now →

Laravel Image Gallery CRUD Example Tutorial

Read Now →

How to disable model timestamps in Laravel?

Read Now →

CRUD (Create Read Update Delete) Example in Laravel 5.2 from Scratch

Read Now →

Laravel Change Date Format using Carbon Example

Read Now →