public function getFavorites() { $posts = Post::whereHas('favored', function ($q) { $q->where('post_user.user_id', Auth::user()->id); })->ordered()->paginate(30); return view('posts.index', compact('posts')); }
public function searchQuestions($keyword) { $posts = Post::whereHas('tags', function ($query) use($keyword) { $query->where('name', 'LIKE', '%' . $keyword . '%'); })->orWhere('title', 'LIKE', '%' . $keyword . '%')->orWhere('body', 'LIKE', '%' . $keyword . '%')->get(); return $posts; }
/** * Fetches all reports that this user can view (not submitted reports). * * @return Collection */ public function getReportedPostsViewable($onlyDirect = false) { return Post::whereHas('reports', function ($query) use($onlyDirect) { $query->whereOpen(); if ($onlyDirect) { $query->whereIn('board_uri', $this->canInBoards('board.reports')); } })->withEverything()->get(); }
/** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function destroy($id) { $post = Post::whereHas('user', function ($q) { $q->where('id', $this->user->id); })->where('id', $id)->get()->first(); if (empty($post)) { return response()->json(['success' => false, 'errors' => ['Not user']], 200); } $post->delete(); return response()->json(['success' => true], 200); }