id = $this->getRandId($this->user_id); $this->expired_at = strtotime('+2 hours'); } public function afterCreate() { $accessTokenCache = new AccessTokenCache(); $accessTokenCache->rebuild($this->id); } protected function getRandId($userId, $prefix = 'AT') { return md5("{$prefix}-{$userId}" . time() . rand(1000, 9999)); } }