title: How to avoid single route in Laravel for Server Sent Events
body: <p>So I am trying to use <a href="https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events" rel="nofollow noreferrer">Server Sent Events</a> in my laravel app but the problem is that in SSE, you can only specify single URL as in:</p>
  
  <pre><code>var evtSource = new EventSource("sse.php");
  </code></pre>
  
  <p>The problem is that I want to send events from different parts/controllers of the entire application not just single <code>sse.php</code> file for example. Example:</p>
  
  <pre><code>// AuthController.php
  public function postLogin(Request $request) {
    // login logic
  
    // SEND SSE EVENT ABOUT NEW USER LOGIN
  }
  
  // FooController.php
  public function sendMessage() {
    // SEND SSE EVENT ABOUT NEW MESSAGE
  }
  </code></pre>
  
  <p>The only idea that comes to my mind is that from these controllers, create temporary files with event text and then read those text files in <code>sse.php</code> file, send events and then delete files. However, this doesn't look like perfect solution. Or maybe hook <code>sse.php</code> file with Laravel events mechanism somehow but that seems kinda advanced.</p>
  
  <p>I also don't mind creating multiple event source objects with different php files like <code>sse.php</code> but problem is that those controllers methods don't necessarily just send events alone, they do other work as well. For example, I cannot use <code>postLogin</code> action directly in SSE object because it also performs the login logic not just sending event.</p>
  
  <p>Has anyone had similar problem and how to tackle with it please ?</p>