| Conditions | 2 |
| Paths | 2 |
| Total Lines | 12 |
| Code Lines | 7 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 23 | public static function findPreviousPost(DiscussPost $post, bool $withSolved = false): ?DiscussPost |
||
| 24 | { |
||
| 25 | $previousPost = DiscussPost::where('id', '!=', $post->getKey()) |
||
| 26 | ->where('conversation_id', $post->conversation->getKey()) |
||
| 27 | ->where('created_at', '<=', $post->created_at); |
||
| 28 | |||
| 29 | if (!$withSolved) { |
||
| 30 | $previousPost = $previousPost->where('id', '!=', $post->conversation->solved_post_id); |
||
| 31 | } |
||
| 32 | |||
| 33 | return $previousPost->orderBy('created_at', 'desc') |
||
| 34 | ->first(); |
||
| 35 | } |
||
| 37 |