0

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); if(!$row){ 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()){ try{ $row->locked_by = Auth::id(); $row->locked_at = date('Y-m-d H:i:s', strtotime("+5 min")); $row->save(); return true; }catch(PDOException $e){ Log::error('Error setting lock at ID:' .$id.': ' . $e->getMessage()); return null; } }else{ 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) { //Do-nothing } 

But still, it updates..

Is there anything I'm missing here?

2
  • have you checked the column in the table? it can also be the cause Commented Jan 18, 2016 at 16:22
  • @BinaryGhost The created_at column is set to timestamp, not null. Is this what it should be? Commented Jan 18, 2016 at 16:24

2 Answers 2

1

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.

Edit

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you, I can't believe I missed this... On the local no 'on update' is set, however on the deployed application it is.. for some reason.
0

You have to check created_at field attribute in table. if its set to 'on Update current timestamp' then change to empty.

I think it may be help full for you.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.