added laravel like touch() method to AutoTimestamp

This commit is contained in:
Carsten Brandt
2014-01-07 05:10:36 +01:00
parent 34dc150f63
commit 01d0323521

View File

@@ -99,4 +99,18 @@ class AutoTimestamp extends Behavior
return time(); return time();
} }
} }
/**
* Updates a timestamp attribute to the current timestamp.
*
* ```php
* $model->touch('lastVisit');
* ```
* @param string $attribute the name of the attribute to update.
*/
public function touch($attribute)
{
$timestamp = $this->evaluateTimestamp();
$this->owner->updateAttributes([$attribute => $timestamp]);
}
} }