How to Update Record Without Updating Timestamp in 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();
}
}
- How to Notifications With database Driver in Laravel 11?
- How to Send Email Via Notification in Laravel 11?
- How to Install and Configure Laravel 11 Debugbar?
- How to Like Dislike System in Laravel 11?
- How to Paginate a Model with Relationship in Laravel 11?
- Laravel 11 Upload Files to Amazon S3 Example
- Laravel 11 Send WhatsApp Messages Example
- Laravel 11 Rest API Authentication Using JWT Tutorial