addBehavior( new SoftDelete([ 'field' => 'deleted', 'value' => 1, ]) ); } public function beforeCreate() { $this->id = $this->getRandId($this->user_id); $this->expired_at = strtotime('+2 hours'); } public function beforeUpdate() { $this->updated_at = time(); } public function afterCreate() { $refreshToken = new RefreshToken(); $refreshToken->user_id = $this->user_id; $refreshToken->create(); } protected function getRandId($userId, $prefix = 'AT') { return md5("{$prefix}-{$userId}" . time() . rand(1000, 9999)); } }