/** * Logic for pulling posts for API updates. * * @param DbQuery $query Provided by Laravel. * @param Board $board * @param Carbon $sinceTime * @param Post $thread Board ID. * @return $query */ public function scopeWhereInUpdate($query, $sinceTime, Board $board, Post $thread) { // Find posts in this board. return $query->where('posts.board_uri', $board->board_uri)->withEverything()->where(function ($query) use($thread) { $query->where('posts.reply_to_board_id', $thread->board_id); $query->orWhere('posts.board_id', $thread->board_id); })->where(function ($query) use($sinceTime) { $query->where('posts.updated_at', '>', $sinceTime); $query->orWhere('posts.deleted_at', '>', $sinceTime); })->withTrashed()->orderBy('posts.board_id', 'asc'); }