Пример #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 delete(Request $request)
 {
     $result = Collect::findOrFail($request->get('id'))->delete();
     if ($result) {
         $this->succeed(true);
     } else {
         $this->setResult('collects表删除记录失败!');
         $this->fail(true);
     }
 }
Пример #3
0
 public function countCollects($id)
 {
     $result = array();
     $cas = CollectArticle::where('article_id', $id)->get();
     foreach ($cas as $c) {
         $collect = Collect::where('id', $c->collect_id)->first();
         if (!in_array($collect->user_id, $result)) {
             array_push($result, $collect->user_id);
         }
     }
     return count($result);
 }
Пример #4
0
 public function delete_collect($collect_id)
 {
     $collect = Collect::find($collect_id);
     if ($collect->delete()) {
         $message = 'Контакт удален!';
     } else {
         $message = 'Произошла ошибка, попробуйте снова!';
     }
     session()->flash('message', $message);
     return redirect()->back();
 }
Пример #5
0
 public function collect($id, $cid)
 {
     $action = 'collects';
     $user = User::findOrFail($id);
     $collect = Collect::findOrFail($cid);
     $collects = Collect::where('user_id', $user->id)->get();
     return view('member.users.collect-show', compact('collect', 'user', 'action', 'collects', 'articles'));
 }
Пример #6
0
 public function collect(Request $request)
 {
     $article = Article::find($request->id, ['id', 'user_id', 'title']);
     if (empty($article)) {
         return response()->json(['status' => 404]);
     }
     $user = Auth::user();
     if ($collect = Collect::isCollect(Auth::user(), $article)) {
         $user->collects()->detach($article->id);
         $article->decrement('collect_count');
         return response()->json(['status' => 200, 'action' => 'down']);
     } else {
         $user->collects()->attach($article->id);
         $article->increment('collect_count');
         Auth::user()->histories()->create(['type' => 'collect', 'content' => '收藏文章《<a href="/article/' . $article->id . '" target="_blank">' . $article->title . '</a>》']);
         return response()->json(['status' => 200, 'action' => 'up']);
     }
 }
Пример #7
0
 public function collectedArticle($id)
 {
     $results = array();
     $collects = Collect::where('user_id', \Auth::user()->id)->get();
     foreach ($collects as $collect) {
         $result = CollectArticle::where(['collect_id' => $collect->id, 'article_id' => $id])->first();
         if ($result) {
             array_push($results, $result);
         }
     }
     return $results;
 }
Пример #8
0
 public static function isCollect(User $user, Article $article)
 {
     return Collect::where('user_id', $user->id)->where('article_id', $article->id)->first();
 }