public function createOrDelete($id)
 {
     $topic = Topic::find($id);
     if (Attention::isUserAttentedTopic(Auth::user(), $topic)) {
         $message = lang('Successfully remove attention.');
         Auth::user()->attentTopics()->detach($topic->id);
     } else {
         $message = lang('Successfully_attention');
         Auth::user()->attentTopics()->attach($topic->id);
         Notification::notify('topic_attent', Auth::user(), $topic->user, $topic);
     }
     flash()->success('hello!', $message);
     return Redirect::route('topics.show', $topic->id);
 }
示例#2
0
 public function createOrDelete($id)
 {
     $topic = Topic::find($id);
     if (Attention::isUserAttentedTopic(auth()->user(), $topic)) {
         $message = lang('Successfully remove attention.');
         auth()->user()->attentTopics()->detach($topic->id);
     } else {
         $message = lang('Successfully_attention');
         auth()->user()->attentTopics()->attach($topic->id);
         Notification::notify('topic_attent', auth()->user(), $topic->user, $topic);
     }
     Flash::success($message);
     return redirect()->route('topics.show', $topic->id);
 }
示例#3
0
 public function post_case(Request $request)
 {
     $user1_id = Auth::id();
     //关注id
     $user2_id = $request->user2_id;
     //被关注id*/
     $attention = Attention::where('user1_id', $user1_id)->where('user2_id', $user2_id)->first();
     if (empty($attention)) {
         Attention::insert(array('user1_id' => $user1_id, 'user2_id' => $user2_id));
         return response()->json(array('status' => 1));
     } else {
         return '已关注';
     }
 }
 public static function isUserAttentedTopic(User $user, Topic $topic)
 {
     return Attention::where('user_id', $user->id)->where('topic_id', $topic->id)->first();
 }
示例#5
0
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function showArticle($aid)
 {
     $user1_id = Auth::id();
     //关注id
     $user2_id = $aid;
     //被关注id*/
     $articles = Article::where('aid', $aid)->get();
     $id = $articles->toArray()[0]['userid'];
     //通过文章的id查找属于用户的id
     $following_count = $this->following($id);
     $followed_count = $this->followed($id);
     $users = User::find($id);
     $Categorys = User::find($id)->hasManyCategorys;
     $attention = Attention::where('user1_id', $user1_id)->where('user2_id', $user2_id)->first();
     $lastArticles = $this->lastPublicArticles($id);
     //获取最近的发表的6篇文章
     return view('article.show', array('articles_title' => $articles[0]->title, 'articles_content' => EndaEditor::MarkDecode($articles[0]->content), 'following_count' => $following_count, 'followed_count' => $followed_count, 'users' => $users, 'Categorys' => $Categorys, 'attention' => $attention, 'lastArticles' => $lastArticles));
 }