CommentController.php 548 B

123456789101112131415161718192021222324
  1. <?php
  2. namespace App\Http\Controllers;
  3. use Illuminate\Http\Request;
  4. use App\Models\Post;
  5. use App\Events\CommentPosted;
  6. class CommentController extends Controller
  7. {
  8. //
  9. public function store(Request $request, Post $post)
  10. {
  11. $validated = $request->validate([
  12. 'author_name' => 'required|string',
  13. 'body' => 'required|string',
  14. ]);
  15. $comment = $post->comments()->create($validated);
  16. CommentPosted::dispatch($comment);
  17. return back()->with('success', 'Успешно!');
  18. }
  19. }