Skip to content

Instantly share code, notes, and snippets.

@devoltt
Created March 11, 2019 10:24
Show Gist options
  • Save devoltt/2f3c090daaaadab3ef0e1d3940c1b4d0 to your computer and use it in GitHub Desktop.
Save devoltt/2f3c090daaaadab3ef0e1d3940c1b4d0 to your computer and use it in GitHub Desktop.
Add timestamps created_at and updated_at on yii2 mongodb
/**
* Add timestamps on create and update records
*
* @return array
*/
public function behaviors()
{
return [
[
'class' => TimestampBehavior::class,
'createdAtAttribute' => 'created_at',
'updatedAtAttribute' => 'updated_at',
'value' => new \MongoDB\BSON\UTCDateTime(),
],
];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment