Laravel Update a Record Without Updating Timestamp Example
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...
Hardik Savani
I'm a full-stack developer, entrepreneur and owner of ItSolutionstuff.com. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- How to Select Specific Columns in Laravel Eloquent Model?
- How to Get All Models in Laravel?
- How to Get Columns Names from Model in Laravel?
- How to Create Model in Laravel using Command?
- Laravel 9 Enum Model Attribute Casting Example
- Laravel 9 Model Events Example Tutorial
- Laravel Eloquent Model Custom Function Example
- How to Create Custom Model Events in Laravel?
- Laravel Replicate Model with Relationships Example
- How to use Laravel Model Observers?
- Laravel Model Disable created_at and updated_at Update Record
- How to disable model timestamps in Laravel?