PremoderateComment.php 682 B

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php
  2. namespace App\Listeners;
  3. use App\Events\CommentAdded;
  4. use Illuminate\Contracts\Queue\ShouldQueue;
  5. use Illuminate\Queue\InteractsWithQueue;
  6. use App\Models\Comment;
  7. use Illuminate\Support\Str;
  8. class PremoderateComment implements ShouldQueue
  9. {
  10. /**
  11. * Create the event listener.
  12. */
  13. public function __construct()
  14. {
  15. //
  16. }
  17. /**
  18. * Handle the event.
  19. */
  20. public function handle(CommentAdded $event): void
  21. {
  22. $comment = $event->comment;
  23. $result = Str::of($comment->content)->match('/(http:|https:)/');
  24. if ($result == "") {
  25. $comment->allow();
  26. } else {
  27. $comment->makePending();
  28. }
  29. }
  30. }