By default Laravel automatically invoke an attribute field to update current timestamp whenever a record have some change or modified via model. The field updated_at
will always refresh update with new timestamp when user submit modified data. Sometime this field might be annoyed for sorting so we don't want to update new timestamp whenever we made some changed to the record.
This article will show you how to modified a record in Laravel without update timestamp. The method to apply is to stop updateting timestamps by set disabled timestamp to false when we updated data in record. To make it clear let's see below example:
Suppose you already have controller file and just want to know the way how to avoid update timestamp on updated_at
field.
Open file app -> Http -> Controllers -> HomeController.php
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\Article;
class HomeController extends Controller
{
public function index()
{
$article = Article::find(2);
//To prevent update timestamp
$article ->timestamps = false;
$post->title = "Disable update_at";
$post->save();
}
}
Hope this would help your project. Have a nice day!!
You might also like...
Founder of CamboTutorial.com, I am happy to share my knowledge related to programming that can help other people. I love write tutorial related to PHP, Laravel, Python, Java, Android Developement, all published post are make simple and easy to understand for beginner. Follow him