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...
As the founder and passionate educator behind this platform, I’m dedicated to sharing practical knowledge in programming to help you grow. Whether you’re a beginner exploring Machine Learning, PHP, Laravel, Python, Java, or Android Development, you’ll find tutorials here that are simple, accessible, and easy to understand. My mission is to make learning enjoyable and effective for everyone. Dive in, start learning, and don’t forget to follow along for more tips and insights!. Follow him