Laravel 5.1 Created_at Timestamp Being Automatically Changed

- 1 answer

I've got a laravel project that is running fine on my local version of Google app engine, however when deployed the created_at timestamp is being changed even though it is set not to.

All of my models have

 public $timestamps = false;

as I need to update certain parts of the row without affecting the timestamps, so I do this manually.

In my repository I have the following function:

public function setLock($id)
    $row = $this->model->find($id);
        return null;
    $row->timestamps = false;
    if($row->locked_at == NULL || strtotime($row->locked_at) < strtotime(date('Y-m-d H:i:s')) || $row->locked_by == Auth::id()){
            $row->locked_by   = Auth::id();
            $row->locked_at   = date('Y-m-d H:i:s', strtotime("+5 min"));
            return true;
        }catch(PDOException $e){
            Log::error('Error setting lock at ID:' .$id.': ' . $e->getMessage());
            return null;
        return false;

Which still updates the created_at timestamp, regardless of if the timestamp variable is set or not, both within the model and the function.

I've also tried setting this function inside the model:

public function setUpdatedAt($value)

But still, it updates..

Is there anything I'm missing here?



Like we discussed in the comments, its the database who is changing the create_at each time the row is updated.

You can remove the default value for the 'create_at' column,

Or you can send the original created_at each time you update the row. this way you will be able to keep the original creation date.


If you decided to set the deafult value to null, make sure that when you insert new rows you update them with the date and time.