а что тут не правильно ?
/**
* Комментарии
*
* @param int $id
* @param Request $request
* @param Validator $validator
* @param Flood $flood
*
* @return string
*/
public function comments(int $id, Request $request, Validator $validator, Flood $flood): string
{
/** @var Article $article */
$item = Item::query()->find($id);
if (! $item) {
abort(404, __('blogs.article_not_exist'));
}
if ($request->isMethod('post')) {
$user = getUser();
$msg = $request->input('msg');
$validator
->true($user, __('main.not_authorized'))
->equal($request->input('token'), $_SESSION['token'], __('validator.token'))
->length($msg, 5, setting('comment_length'), ['msg' => __('validator.text')])
->false($flood->isFlood(), ['msg' => __('validator.flood', ['sec' => $flood->getPeriod()])]);
if ($validator->isValid()) {
/** @var Comment $comment */
$comment = $item->comments()->create([
'text' => antimat($msg),
'user_id' => $user->id,
'created_at' => SITETIME,
'ip' => getIp(),
'brow' => getBrowser(),
]);
$user->increment('allcomments');
$user->increment('point');
$user->increment('money', 5);
$item->increment('count_comments');
$flood->saveState();
sendNotify($msg, '/articles/comment/' . $item->id . '/' . $comment->id, $item->title);
setFlash('success', __('main.comment_added_success'));
redirect('/articles/end/' . $item->id);
} else {
setInput($request->all());
setFlash('danger', $validator->getErrors());
}
}
$comments = $item->comments()
->with('user')
->orderBy('created_at')
->paginate(setting('comments_per_page'));
return view('blogs/comments', compact('article', 'comments'));
}