Laravel Update a Record Without Updating Timestamp Tutorial

Feb 06, 2023 . Admin



Hi dev,

This article provides the most interesting examples of Laravel update records without update timestamps. I'll show you how to update a Laravel record without changing its timestamp. You will discover in Laravel how to update without a timestamp. The Laravel update query is presented without the update timestamp.

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();
    
    }
}	

I hope it can help you...

#Laravel