示例#1
0
 public static function add($topic, $user)
 {
     try {
         return static::create(['topic_id' => $topic->topic_id, 'user_id' => $user->user_id]);
     } catch (QueryException $ex) {
         // Do nothing if already watching. Rethrow everything else.
         if (!is_sql_unique_exception($ex)) {
             throw $ex;
         }
     }
 }
示例#2
0
文件: User.php 项目: ppy/osu-web
 public function profileCustomization()
 {
     if ($this->profileCustomization === null) {
         try {
             $this->profileCustomization = $this->userProfileCustomization()->firstOrCreate([]);
         } catch (Exception $ex) {
             if (is_sql_unique_exception($ex)) {
                 // retry on duplicate
                 return $this->profileCustomization();
             }
             throw $ex;
         }
     }
     return $this->profileCustomization;
 }
示例#3
0
 public function favourite($user)
 {
     DB::transaction(function () use($user) {
         try {
             FavouriteBeatmapset::create(['user_id' => $user->user_id, 'beatmapset_id' => $this->beatmapset_id]);
         } catch (QueryException $e) {
             if (is_sql_unique_exception($e)) {
                 return;
             } else {
                 throw $e;
             }
         }
         $this->favourite_count = DB::raw('favourite_count + 1');
         $this->save();
     });
 }