Laravel How To Update Record without Updating Timestamp

Reading Time: 2 minutes
903 Views

Inside this article we will see the concept i.e Laravel How To Update Record without Updating Timestamp. Article contains the classified information i.e Laravel saving without updating Timestamp.

When we explore application in some advanced features then at some point we need to alter table and it’s properties. So, here in this short tutorial we will see How to update data to existing table of laravel without updating timestamp concept.

Read More: How To Convert a Integer To Roman Numeral in PHP

Let’s get started.

Laravel Installation

Open terminal and run this command to create a laravel project.

composer create-project laravel/laravel myblog

It will create a project folder with name myblog inside your local system.

To start the development server of laravel –

php artisan serve

URL: http://127.0.0.1:8000

Assuming laravel already installed inside your system.

Update Record without Timestamps

Let’s consider a Controller here to understand the process of update.

<?php
    
namespace App\Http\Controllers;
    
use Illuminate\Http\Request;
use App\Models\Post;
   
class PostController 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 = "Post updated";
        $post->content = "More Post content added";
  
        $post->save();
    }
}

Concept

We can update any amount of data by just adding this line of code to prevent to update timestamps column of database table.

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

We hope this article helped you to learn about Laravel How To Update Record without Updating Timestamp Tutorial in a very detailed way.

Read More: Convert a Roman Numeral To a Number in PHP

Online Web Tutor invites you to try Skillshike! Learn CakePHP, Laravel, CodeIgniter, Node Js, MySQL, Authentication, RESTful Web Services, etc into a depth level. Master the Coding Skills to Become an Expert in PHP Web Development. So, Search your favourite course and enroll now.

If you liked this article, then please subscribe to our YouTube Channel for PHP & it’s framework, WordPress, Node Js video tutorials. You can also find us on Twitter and Facebook.