コード例 #1
0
ファイル: PostController.php プロジェクト: enhive/vev
 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'));
 }
コード例 #2
0
 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;
 }
コード例 #3
0
ファイル: User.php プロジェクト: Ryangr0/infinity-next
 /**
  * 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();
 }
コード例 #4
0
ファイル: PostController.php プロジェクト: Iloveall/stihi
 /**
  * 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);
 }