Skip to content

All topics  /  Laravel

How to Update Record Without Updating Timestamp in Laravel?

Laravel ·

Hi dev,

The most significant examples of Laravel update records without update timestamps are provided in this article. I'll demonstrate how to change a record in Laravel without altering the timestamp. In Laravel, you will learn how to update without using a timestamp. Laravel update query without update timestamp is visible.

On sometimes, we wish to make changes to records in a database table without making changes to the timestamps (updated at column). Then, to stop updating timestamps, we may make $model->timestamps = false; in Laravel. So let's look at the basic code:

Example:


app/Http/Controllers/DemoController.php

<?php

    
namespace App\Http\Controllers;

    
use Illuminate\Http\Request;
use App\Models\Post;

   
class DemoController extends Controller
{
    /**
     * Write code on Method
     *
     * @return response()
     */
    public function index(Request $request)
    {
        $post = Post::first();

   
        /* Prevents timestamps auto-update */
        $post->timestamps = false;

  
        $post->title = "Demo Updated";

  
        $post->save();

    
    }
}