Browse Source

编辑话题

wzq 5 years ago
parent
commit
a657990419
1 changed files with 5 additions and 0 deletions
  1. 5 0
      app/Repositories/TopicRepository.php

+ 5 - 0
app/Repositories/TopicRepository.php

@@ -101,6 +101,7 @@ class TopicRepository {
                 'status_code'   => 500
             ]);
         }
+        $oldName = $topic->name;
         $_topic = $this->topic->where(['name'=>$request['name']])->where('id','<>',$topic->id)->first();
         if($_topic){
             return Response::create([
@@ -135,6 +136,10 @@ class TopicRepository {
                 }
             }
             DB::commit();
+            if($oldName != $topic->name){
+                Redis::zrem('topic.name', $oldName);
+                Redis::zadd('topic.name', $topic->id, $topic->name);
+            }
             return Response::create();
         }catch (QueryException $exception){
             DB::rollBack();