Laravel Update a Record Without Updating Timestamp Example

By Hardik Savani April 16, 2024 Category : Laravel

Hi Folks,

This article will provide some of the most important example laravel update record without update timestamp. I’m going to show you about how to update a record without updating timestamp in laravel. you will learn update without update timestamp in laravel. you can see laravel update query without update timestamp.

You can use these tips with laravel 6, laravel 7, laravel 8, laravel 9, laravel 10 and laravel 11 versions.

Sometimes, we want to update records on the database table but don't want to update timestamps(updated_at column). Then how you can do it will laravel, we can make $model->timestamps = false; to stop updating timestamps. so let's see the simple 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...

Tags :
Shares