title: Laravel Blade foreach if relation present
body: <p>I have a project with Users that have Events they can subscribe to (Many to many).
  Everything is working fine but I'm wondering how in my blade view I can see if the user is subscribed to an event or not. </p>
  
  <p>This is my code to load the view with the relation</p>
  
  <pre><code>    $events = Event::with('users')-&gt;get();
      return view('dashboard.events')-&gt;with('events', $events);
  </code></pre>
  
  <p>Now I'm wondering in my view how I can check if a user already has a event subscribed and </p>
  
  <p><strong>if so then don't show the subscribe button for that event</strong></p>
  
  <pre><code>@foreach($events as $event)
      &lt;tr&gt;
          &lt;td&gt;{{ $event-&gt;name }}&lt;/td&gt;
          &lt;td&gt;&lt;a href="/events/subscribe/{{ $event-&gt;id }}"&gt;Subscribe&lt;/a&gt;&lt;/td&gt;
      &lt;/tr&gt;
  @endforeach
  </code></pre>
  
  <h1>Edit 1</h1>
  
  <p>This is not giving errors, but also not working. I'm getting twice the a href version.</p>
  
  <pre><code> @if($event-&gt;users-&gt;contains($event-&gt;id))
       &lt;td&gt;Subscribed&lt;/td&gt;
   @else
       &lt;td&gt;&lt;a href="/events/subscribe/{{ $event-&gt;id }}"&gt;Subscribe&lt;/a&gt;&lt;/td&gt;
   @endif
  </code></pre>