ExportFailed.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. namespace App\Events;
  3. use Illuminate\Broadcasting\Channel;
  4. use Illuminate\Broadcasting\InteractsWithSockets;
  5. use Illuminate\Broadcasting\PresenceChannel;
  6. use Illuminate\Broadcasting\PrivateChannel;
  7. use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
  8. use Illuminate\Foundation\Events\Dispatchable;
  9. use Illuminate\Queue\SerializesModels;
  10. class ExportFailed implements ShouldBroadcast
  11. {
  12. use Dispatchable, InteractsWithSockets, SerializesModels;
  13. public $userId;
  14. public $errorMessage;
  15. public $message;
  16. /**
  17. * Create a new event instance.
  18. */
  19. public function __construct($userId, $errorMessage)
  20. {
  21. $this->userId = $userId;
  22. $this->errorMessage = $errorMessage;
  23. $this->message = 'Export fallito. Riprova o contatta il supporto.';
  24. }
  25. /**
  26. * Get the channels the event should broadcast on.
  27. */
  28. public function broadcastOn()
  29. {
  30. return new PrivateChannel('exports.' . $this->userId);
  31. }
  32. /**
  33. * Get the data to broadcast.
  34. */
  35. public function broadcastWith()
  36. {
  37. return [
  38. 'type' => 'export_failed',
  39. 'message' => $this->message,
  40. 'error' => $this->errorMessage,
  41. 'timestamp' => now()->toISOString()
  42. ];
  43. }
  44. /**
  45. * The event's broadcast name.
  46. */
  47. public function broadcastAs()
  48. {
  49. return 'export.failed';
  50. }
  51. }