You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
1.2 KiB

  1. <?php
  2. namespace App\Listeners;
  3. use App\Events\ModelSaved;
  4. use App\Notifications\SocketNotification;
  5. use Illuminate\Contracts\Queue\ShouldQueue;
  6. use Illuminate\Queue\InteractsWithQueue;
  7. use Illuminate\Support\Facades\Notification;
  8. class NotifHandler
  9. {
  10. /**
  11. * Create the event listener.
  12. *
  13. * @return void
  14. */
  15. public function __construct()
  16. {
  17. //
  18. }
  19. /**
  20. * Handle the event.
  21. *
  22. * @param ModelSaved $event
  23. * @return void
  24. */
  25. public function handle(ModelSaved $event)
  26. {
  27. $message = json_decode($event->message);
  28. $event_class = 'App\Events\\'.enum('tables.'.$message->data->table_name.'.singular_name').enum('cruds.inverse.'.$message->data->crud_id.'.name');
  29. if (class_exists($event_class)) {
  30. $event_class::dispatch($message);
  31. }
  32. if (auth()->user()) {
  33. Notification::send(auth()->user(), new SocketNotification(
  34. [
  35. 'message' => enum('tables.'.$message->data->table_name.'.singular_name').enum('cruds.inverse.'.$message->data->crud_id.'.name'),
  36. 'payload'=> request('_business_info') ?? null
  37. ]));
  38. }
  39. }
  40. }