mirror of
https://github.com/yiisoft/yii2.git
synced 2025-12-01 23:51:12 +08:00
added laravel like touch() method to AutoTimestamp
This commit is contained in:
@@ -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]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user