CommentController.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Models\Post;
  4. use App\Models\Comment;
  5. use Illuminate\Http\Request;
  6. class CommentController extends Controller
  7. {
  8. public function store(Request $request, Post $post)
  9. {
  10. $validated = $request->validate([
  11. 'author_name' => 'required|max:255',
  12. 'author_email' => 'required|email',
  13. 'content' => 'required|max:1000',
  14. ]);
  15. $post->comments()->create($validated);
  16. return redirect()->route('posts.show', $post)
  17. ->with('success', 'Комментарий отправлен на модерацию');
  18. }
  19. public function moderate()
  20. {
  21. $comments = Comment::pending()->with('post')->latest()->paginate(20);
  22. return view('comments.moderate', compact('comments'));
  23. }
  24. public function approve(Comment $comment)
  25. {
  26. $comment->approve();
  27. return back()->with('success', 'Комментарий одобрен');
  28. }
  29. public function reject(Comment $comment)
  30. {
  31. $comment->reject();
  32. return back()->with('success', 'Комментарий отклонен');
  33. }
  34. }