Code Duplication    Length = 27-27 lines in 2 locations

app/Http/Controllers/Blog/CommentController.php 1 location

@@ 66-92 (lines=27) @@
63
     *
64
     * @return \Illuminate\Http\RedirectResponse
65
     */
66
    public function show(Request $request, int $id): RedirectResponse
67
    {
68
        $comment = Comment::findOrFail($id);
69
70
        $commentsBefore = Comment::where([
71
            ['article_id', $comment->article_id],
72
            ['created_at', '<', $comment->created_at]
73
        ])->count();
74
75
        $commentsPerPage = config('xetaravel.pagination.blog.comment_per_page');
76
77
        $page = floor($commentsBefore / $commentsPerPage) + 1;
78
        $page = ($page > 1) ? $page : 1;
79
80
        $request->session()->keep(['primary', 'danger', 'warning', 'success', 'info']);
81
82
        return redirect()
83
            ->route(
84
                'blog.article.show',
85
                [
86
                    'slug' => $comment->article->slug,
87
                    'id' => $comment->article->id,
88
                    'page' => $page,
89
                    '#comment-' . $comment->getKey()
90
                ]
91
            );
92
    }
93
}
94

app/Http/Controllers/Discuss/PostController.php 1 location

@@ 57-83 (lines=27) @@
54
     *
55
     * @return \Illuminate\Http\RedirectResponse
56
     */
57
    public function show(Request $request, int $id): RedirectResponse
58
    {
59
        $post = DiscussPost::findOrFail($id);
60
61
        $postsBefore = DiscussPost::where([
62
            ['conversation_id', $post->conversation_id],
63
            ['created_at', '<', $post->created_at]
64
        ])->count();
65
66
        $postsPerPage = config('xetaravel.pagination.discuss.post_per_page');
67
68
        $page = floor($postsBefore / $postsPerPage) + 1;
69
        $page = ($page > 1) ? $page : 1;
70
71
        $request->session()->keep(['primary', 'danger', 'warning', 'success', 'info']);
72
73
        return redirect()
74
            ->route(
75
                'discuss.conversation.show',
76
                [
77
                    'slug' => $post->conversation->slug,
78
                    'id' => $post->conversation->id,
79
                    'page' => $page,
80
                    '#post-' . $post->getKey()
81
                ]
82
            );
83
    }
84
85
    /**
86
     * Mark as solved.