浏览代码

Update Status model

Daniel Supernault 6 年之前
父节点
当前提交
7d7a64382b
共有 1 个文件被更改,包括 11 次插入6 次删除
  1. 11 6
      app/Status.php

+ 11 - 6
app/Status.php

@@ -150,9 +150,11 @@ class Status extends Model
         if(Auth::check() == false) {
             return false;
         }
-        return Cache::remember('status:'.$this->id.':likedby:userid:'.Auth::id(), now()->addHours(30), function() {
-            $profile = Auth::user()->profile;
-            return Like::whereProfileId($profile->id)->whereStatusId($this->id)->count();
+        $user = Auth::user();
+        $id = $this->id;
+        return Cache::remember('status:'.$this->id.':likedby:userid:'.$user->id, now()->addHours(30), function() use($user, $id) {
+            $profile = $user->profile;
+            return Like::whereProfileId($profile->id)->whereStatusId($id)->count();
         });
     }
 
@@ -193,9 +195,12 @@ class Status extends Model
         if(Auth::check() == false) {
             return false;
         }
-        $profile = Auth::user()->profile;
-
-        return self::whereProfileId($profile->id)->whereReblogOfId($this->id)->count();
+        $user = Auth::user();
+        $id = $this->id;
+        return Cache::remember('status:'.$this->id.':sharedby:userid:'.$user->id, now()->addHours(30), function() use($user, $id) {
+            $profile = $user->profile;
+            return self::whereProfileId($profile->id)->whereReblogOfId($id)->count();
+        });
     }
 
     public function sharedBy()