Laravel 5.2 - How to update "updated_at" field with UTC timestamp?

I'm using Laravel 5.2 (on PHP version 7) and below is the update query I'm running:

$data=DB::table('posts')
                        ->where("id", $post_id)
                        ->update(
                            array(
                                'title'         =>      $request['title'],
                                'body'          =>      $request['body'],
                                'slug'          =>      str_slug($request['title']),
                                'updated_at'    =>      DB::raw('CURRENT_TIMESTAMP')
            ));

The "updated_at" field updated with the current time. But I want to update it with the UTC timestamp. How can I achieve this?

Upvotes: 0

Views: 1085

Answers (1)

Jeremy French
Jeremy French

Reputation: 12167

If you use the model->save() method it should handle created and updated dates for you. In general you should not need to do raw DB updates in Laravel.

If you wish to have a different timezone for this then look at the timezone setting in app.php. The default however is 'UTC' so you should not have to worry.

Upvotes: 1

Related Questions