lundi 18 janvier 2016

Laravel 5.1 created_at timestamp being automatically changed

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?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire