1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Xetaravel\Http\Controllers\Blog; |
6
|
|
|
|
7
|
|
|
use Illuminate\Database\Eloquent\ModelNotFoundException; |
8
|
|
|
use Illuminate\Http\RedirectResponse; |
9
|
|
|
use Illuminate\Http\Request; |
10
|
|
|
use Xetaravel\Http\Controllers\Controller; |
11
|
|
|
use Xetaravel\Models\BlogComment; |
12
|
|
|
|
13
|
|
|
class CommentController extends Controller |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* Redirect a user to an article, page and comment. |
17
|
|
|
* |
18
|
|
|
* @param Request $request |
19
|
|
|
* @param int $id The ID of the comment. |
20
|
|
|
* |
21
|
|
|
* @return RedirectResponse |
22
|
|
|
* |
23
|
|
|
* @throws ModelNotFoundException |
24
|
|
|
*/ |
25
|
|
|
public function show(Request $request, int $id): RedirectResponse |
26
|
|
|
{ |
27
|
|
|
$comment = BlogComment::findOrFail($id); |
28
|
|
|
|
29
|
|
|
$commentsBefore = BlogComment::where([ |
30
|
|
|
['blog_article_id', $comment->blog_article_id], |
|
|
|
|
31
|
|
|
['created_at', '>', $comment->created_at] |
|
|
|
|
32
|
|
|
])->count(); |
33
|
|
|
|
34
|
|
|
$commentsPerPage = config('xetaravel.pagination.blog.comment_per_page'); |
35
|
|
|
|
36
|
|
|
$page = floor($commentsBefore / $commentsPerPage) + 1; |
37
|
|
|
$page = ($page > 1) ? $page : 1; |
38
|
|
|
|
39
|
|
|
$request->session()->keep(['primary', 'error', 'warning', 'success', 'info']); |
40
|
|
|
|
41
|
|
|
return redirect() |
42
|
|
|
->route( |
|
|
|
|
43
|
|
|
'blog.article.show', |
44
|
|
|
[ |
45
|
|
|
'slug' => $comment->article->slug, |
|
|
|
|
46
|
|
|
'id' => $comment->article->id, |
47
|
|
|
'page' => $page, |
48
|
|
|
'#comment-' . $comment->getKey() |
49
|
|
|
] |
50
|
|
|
); |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
|