SendActionEmailNotification.php 951 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. namespace App\Listeners;
  3. use App\Events\ObjectActionCreate;
  4. use App\Models\Enums\ActionObjectType;
  5. use App\Models\Enums\ObjectAction;
  6. use Illuminate\Contracts\Queue\ShouldQueue;
  7. use Illuminate\Queue\InteractsWithQueue;
  8. class SendActionEmailNotification 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(ObjectActionCreate $event): void
  21. {
  22. }
  23. public function shouldQueue(ObjectActionCreate $event): bool
  24. {
  25. $actionObjectType = ActionObjectType::tryFrom($event->action->object_type);
  26. $objectAction = ObjectAction::tryFrom($event->action->action);
  27. if (! $actionObjectType || !$objectAction) {
  28. return false;
  29. }
  30. return in_array($objectAction->value, $event->notificationSetting[$actionObjectType->value]['email'] ?? []);
  31. }
  32. }