title: How to do Laravel Eloquent multiple joins with conditions properly?
body: <p>I am trying to convert an old php code to Laravel and I came across a complicated query statement with a lot of joins and conditions. I tried converting the query statement (see 2nd image), but the results I am getting is different. The total rows for original code returns 13,340 rows, when I tried executing the laravel version, I was getting a <code>PHP Fatal error:  Allowed memory size of 134217728 bytes exhausted (tried to allocate 41553920 bytes)</code> due to the rows being so many which probably means that there is something wrong with the query I made.</p>
  
  <p>Original PHP Code:<a href="https://i.stack.imgur.com/aIMQP.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/aIMQP.png" alt="enter image description here"></a></p>
  
  <p>Eloquent Version: <a href="https://i.stack.imgur.com/e0Ktp.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/e0Ktp.png" alt="enter image description here"></a></p>