title: How to retrieve data with composite primary key in Laravel
body: <p>I am working with four tables in Laravel and trying to display data to a view.  I believe I am stuck because one of the tables has a composite primary key.</p>
  
  <p>I have the following in my controller:</p>
  
  <pre><code>public function show($id)
  {
      //Get application for drug
      $application = PharmaApplication::where('ApplNo', $id)-&gt;first();
  
      //Return all products for application
      $drugs = $application-&gt;products;
  
      return view('profiles.drug', compact('drugs'));
  }
  </code></pre>
  
  <p>I have the following in my PharmaApplication model:</p>
  
  <pre><code>public function products()
  {
      return $this-&gt;hasMany('App\PharmaProduct', 'ApplNo', 'ApplNo');
  }
  </code></pre>
  
  <p>I have the following in my view (which I cannot complete)</p>
  
  <pre><code>@foreach ($drugs as $drug) 
    &lt;li&gt;{{$drug-&gt;Strength}}&lt;/li&gt;
    &lt;li&gt;{{$drug-&gt;Form}}&lt;/li&gt;
    &lt;li&gt;{{$drug-&gt;Form}}&lt;/li&gt;
  @endforeach
  </code></pre>
  
  <p>I am trying to accomplish the following:</p>
  
  <ol>
  <li>Get the application for a drug - this part of my code works</li>
  <li>Return an array of objects for the products (i.e. 7 products that belong to one application). I can do this but get stuck going to the next part.</li>
  <li>Next, I have to use the array of objects and search a table with the following columns: MarketingStatusID, ApplNo, ProductNo. I know how to query this table and get one row using DB Query, but then how do I get the proper result to that query within the for loop in my view?</li>
  <li>Finally, I use the MarketingStatusID to retrieve the MarketingStatusDescription which I will know how to do.</li>
  </ol>