| 123456789101112131415161718192021222324252627282930313233343536373839404142 |
- <?php
- namespace App\Http\Controllers;
- use App\Models\Post;
- use App\Models\Comment;
- use Illuminate\Http\Request;
- class CommentController extends Controller
- {
- public function store(Request $request, Post $post)
- {
- $validated = $request->validate([
- 'author_name' => 'required|max:255',
- 'author_email' => 'required|email',
- 'content' => 'required|max:1000',
- ]);
- $post->comments()->create($validated);
- return redirect()->route('posts.show', $post)
- ->with('success', 'Комментарий отправлен на модерацию');
- }
- public function moderate()
- {
- $comments = Comment::pending()->with('post')->latest()->paginate(20);
- return view('comments.moderate', compact('comments'));
- }
- public function approve(Comment $comment)
- {
- $comment->approve();
- return back()->with('success', 'Комментарий одобрен');
- }
- public function reject(Comment $comment)
- {
- $comment->reject();
- return back()->with('success', 'Комментарий отклонен');
- }
- }
|