| 12345678910111213141516171819202122232425262728293031 |
- <?php
- namespace App\Http\Controllers;
- use Illuminate\Http\Request;
- use App\Models\Comment;
- use App\Models\Post;
- use App\Events\CommentCreated;
- class CommentController extends Controller
- {
- public function index(){
- return view('comments.moderation', ['unapprovedComments' => Comment::where('is_approved', false)->get()]);
- }
- public function store(Request $request, Post $post){
- $comment = $post->comments()->create($request->validate([
- 'author_name' => 'required',
- 'content' => 'required'
- ]));
- event(new CommentCreated($comment));
- return back()->with('success', 'Комментарий отправлен на модерацию');
- }
-
- public function approve($id) {
- $comment = Comment::findOrFail($id);
- $comment->update(['is_approved' => true]);
- return back()->with('success', 'Комментарий одобрен');
- }
- }
|