Laravel Set Model Timestamps False

10-Apr-2023

.

Admin

Hi Dev,

In this article I will teach you how to set model timestamps false in laravel. set timestamps false into model in laravel. You can easy to understand and how to use it.

Sometimes we require to disable created_at and updated_at timestamps on Model on Laravel, so we can do it simply by using.

$timestamps variable of model and set into false. You can create new item or user using model at that time created_at and updated_at set default.

I am creating new records using create method of model like as bellow example:

Blog::create(['title' => 'nicesnippets.com']); 

Ok, above code will simple to add new records on blogs table with current timestamps value in created_at and updated_at.example as bellow

app/Blog.php


<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Item extends Model

{

public $fillable = ['title'];

public $timestamps = false;

}

It will help you...

#Laravel 7