title: Reference Relationship ID on CSV import
body: <p>I have 2 models that I want to populate by a CVS import. The first model is a list of Retail Stores and the second model is the Retail Stores corresponding locations. </p>
  
  <p>This is the CSV import:</p>
  
  <pre><code>name,email,website,street_number,street_address,city,country,postcode,latitude,longitude
  "Example name",info@example.com,10,"random street",amsterdam,netherlands,4000,52.666,4.3333
  </code></pre>
  
  <p>The <code>RetailStores.php</code> model will need these values:</p>
  
  <pre><code>name,
  email,
  website
  </code></pre>
  
  <p>The <code>LocationStores.php</code> model will need these values:</p>
  
  <pre><code>street_number,
  street_address,
  city,
  country,
  postcode,
  latitude,
  longitude
  </code></pre>
  
  <p>I will extract the data from the CSV file inside a <code>foreach</code> loop and attaching them to an empty array variable, from here will use some <code>Eloquent</code> to populate the database. Below is how I do this:</p>
  
  <pre><code>$file = Input::file('csv_file');
  $data = $this-&gt;retailer-&gt;processCsv($file);
  
  $retailers = [];
  $locations = [];
  
  
  foreach ($data as $value) {
  
     $retailers[] = array(
        'user_id' =&gt; Auth::user()-&gt;id,
        'name' =&gt; $value['name'],
        'email' =&gt; $value['email'],
        'website' =&gt; $value['website'],
        'created_at' =&gt; Carbon::now(),
        'updated_at' =&gt; Carbon::now()
     );
  
     $locations[] = array(
        'retailer_id' =&gt; $value['retailer_id'], // ISSUE HERE
        'street_number' =&gt; $value['street_number'],
        'street_address' =&gt; $value['street_address'],
        'city' =&gt; $value['city'],
        'state' =&gt; $value['state'],
        'country' =&gt; $value['country'],
        'country_code' =&gt; $value['country_code'],
        'postcode' =&gt; $value['postcode'],
        'latitude' =&gt; $value['latitude'],
        'longitude' =&gt; $value['longitude'],
        'created_at' =&gt; Carbon::now(),
        'updated_at' =&gt; Carbon::now()
     );
  
    Retailer::insert($retailers);
    Location::insert($locations);
  }
  </code></pre>
  
  <p>As noted above I have 2 separate models the <em>Retailers</em> and <em>Locations</em>. I need to reference the Retailer ID in the <code>$locations</code> array. For now I have one option which is to have users enter the relevant retailer store id for each location in the CSV file, but people are well.... you know. </p>
  
  <p>However considering that the CSV file will supply a <strong>"Store Name"</strong> for each location it has, is there not a way to reference an increment <strong>ID</strong> for each unique store name within the array? for example if the CSV table had these values:</p>
  
  <pre><code>Fruit,info@fruit.com,www.fruit.com,1,"apple street",etc
  Fruit,info@fruit.com,www.fruit.com,120,"pear parkway",etc
  Fruit,info@fruit.com,www.fruit.com,350,"orange avenue",etc
  Meat,info@meat.com,www.meat.com,33,"Steak street",etc
  Meat,info@meat.com,www.meat.com,33,"Chicken Road",etc
  </code></pre>
  
  <p>When getting these values within the <strong>foreach</strong> loop, is there a way one could give an increment ID for each of the repeated Store names which would thus reference the relevant store to its location?</p>
  
  <p>Any advice, greatly appreciated.  </p>