Laravel – How to disable created_at and updated_at timestamps from Model?
In this post we will give you information about Laravel – How to disable created_at and updated_at timestamps from Model?. Hear we will give you detail about Laravel – How to disable created_at and updated_at timestamps from Model?And how to use it also give you demo for it if it is necessary.
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.
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/Item.php
<?php
namespace App;
use IlluminateDatabaseEloquentModel;
class Item extends Model
{
protected $fillable = ['title','content'];
public $timestamps = false;
}
Now, we can also use another way to update timestamps value of created_at and update_at. In this bellow example you can modify value of created_at and updated_at column value as bellow example:
app/Item.php
<?php
namespace App;
use IlluminateDatabaseEloquentModel;
class Item extends Model
{
protected $fillable = ['title','content'];
public function setUpdatedAt($value)
{
return NULL;
}
public function setCreatedAt($value)
{
return NULL;
}
}
I hope it can help you…
Hope this code and post will helped you for implement Laravel – How to disable created_at and updated_at timestamps from Model?. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs