Пример #1
0
 public function show($id)
 {
     $userId = \Auth::user()->id;
     $article = Article::findOrFail($id);
     if ($userId != $article->user_id) {
         //作者本人访问不增加文章浏览量
         Article::where('id', $id)->increment('view');
         //博主访客+1
         $r = FlowTrace::where(['user_id' => $article->user_id, 'time' => substr(Carbon::now(), 0, 10)])->first();
         if ($r) {
             $r->increment('daycount');
         } else {
             FlowTrace::create(array('user_id' => $article->user_id, 'time' => substr(Carbon::now(), 0, 10), 'daycount' => 1));
         }
         //博主积分+1
         User::where('id', $article->user_id)->increment('score');
     }
     $tags = Tag::where(['user_id' => \Auth::user()->id, 'article_id' => $id])->get();
     $followAuthor = FollowAuthor::where(['my_id' => \Auth::user()->id, 'user_id' => $article->user_id])->first();
     $recommend = false;
     $record = RecommendArticle::where(['user_id' => \Auth::user()->id, 'article_id' => $id])->first();
     if ($record) {
         $recommend = true;
     }
     $collects = Collect::where('user_id', $userId)->get();
     $collected = \Auth::user()->collectedArticle($article->id);
     // if(is_null($article)){
     // 	abort(404);
     // }
     return view('member.articles.show', compact('userId', 'article', 'tags', 'followAuthor', 'recommend', 'collects', 'collected'));
 }
Пример #2
0
 public function addFollowAuthor(Request $request)
 {
     $result = FollowAuthor::firstOrCreate(array('my_id' => \Auth::user()->id, 'user_id' => $request->get('id')));
     if ($result) {
         $this->setResult("关注成功");
         $this->succeed(true);
     } else {
         $this->setResult("关注失败");
         $this->fail(true);
     }
 }
Пример #3
0
 public function countFollowers($useId)
 {
     return FollowAuthor::where('user_id', $useId)->get()->count();
 }
Пример #4
0
 public function searchUser(Request $request)
 {
     switch ($request->get('type')) {
         case 0:
             $r = User::where('name', 'like', '%' . $request->get('name') . '%')->get();
             break;
         case 1:
             $r = array();
             $follows = FollowAuthor::where('id', \Auth::user()->id)->get();
             foreach ($follows as $follow) {
                 array_push($r, User::findOrFail($follow->user_id));
             }
             break;
         default:
             $r = array();
             $follows = FollowAuthor::where('user_id', \Auth::user()->id)->get();
             foreach ($follows as $follow) {
                 array_push($r, User::findOrFail($follow->id));
             }
             break;
     }
     if ($r) {
         $this->setResult($r);
         $this->succeed(true);
     } else {
         $this->fail(true);
     }
 }