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

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