title: Querying a value from two related table in laravel
body: <p>I have related tables events and tickets which are related</p>
  
  
  
  <pre class="lang-php prettyprint-override"><code>class Event {
    public function tickets(){
      return $this-&gt;hasMany(Ticket::class);
    }
  }
  
  class Ticket {
    public function events(){
      return $this-&gt;belongsTo(Event::class);
    }
  }
  </code></pre>
  
  <p>I have a store function getting data from and route URL</p>
  
  <pre class="lang-php prettyprint-override"><code>$ticket=new Ticket;
  $ticket-&gt;userName= $request-&gt;input('userName');
  $ticket-&gt;userEmail= $request-&gt;input('userEmail');
  $ticket-&gt;phoneNumber= $request-&gt;input('phoneNumber');
  $ticket-&gt;regular_quantity= $request-&gt;input('regular_quantity');
  $ticket-&gt;vip_quantity= $request-&gt;input('vip_quantity');
  $ticket-&gt;event_id=$request-&gt;route('id');
  </code></pre>
  
  <p>I have a variable <code>max_attendees</code> which I want to query the maximum attendees which is a column in events table where event id is </p>
  
  <pre class="lang-php prettyprint-override"><code>$ticket-&gt;event_id=$request-&gt;route('id');
  </code></pre>
  
  <p>query</p>
  
  <pre class="lang-php prettyprint-override"><code>$maximum_attendants=\App\Models\Event::with('Max_attendies')-&gt;where('id','=='$event_id');
  </code></pre>
  
  <p>events table
  <a href="https://i.stack.imgur.com/iVJTK.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/iVJTK.png" alt="enter image description here"></a></p>
  
  <p>I have tried this but giving me syntax error, <strong>unexpected 'event_id' (T_STRING), expecting ')'</strong></p>