public function like($way, $id)
 {
     //登录权限限制
     if (!\Session::has('user.uid')) {
         return redirect('/login');
     }
     $userid = \Session::get('user.uid');
     $storyBoardLikeModel = StoryBoardLikeModel::where(['uid' => $userid, 'sbid' => $id])->first();
     if ($storyBoardLikeModel) {
         StoryBoardLikeModel::where('id', $storyBoardLikeModel->id)->delete();
     } else {
         $create = array('uid' => $userid, 'sbid' => $id);
         StoryBoardLikeModel::create($create);
     }
     //确定所在页面:1index,2show
     if ($way == 2) {
         return redirect('/storyboard/' . $id);
     } elseif ($way == 1) {
         return redirect('/storyboard');
     }
 }
示例#2
0
 public function getLike()
 {
     $likeModels = StoryBoardLikeModel::where('sbid', $this->id)->get();
     return $likeModels ? count($likeModels) : 0;
 }