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

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