title: Seeding Models from a CSV file with Eloquent
body: <p>I'm new to laravel, so warning in advance that this might be a no-brainer.</p>
  
  <p>I'm trying to seed a couple of Models with a CSV file. The file contans a list of names and locations of stores. Let's say it looks like this:</p>
  
  <pre><code>StoreName, City, State
  store1, Philadelphia, PA
  store2, Philadelphia, PA
  store3, Altoona, PA
  store4, Portland, OR
  store5, Portland, OR
  </code></pre>
  
  <p>At the end, the result will be a City Model and a State Model. City would have columns for the name of the city, state, and total stores in that city:</p>
  
  <pre><code>id, name, state, total
  1, Philadelphia, PA, 2
  2, Altoona, PA, 1
  3, Portland, OR, 2
  </code></pre>
  
  <p>And the State Model will have columns for name, and total stores in that state:</p>
  
  <pre><code>id, name, total
  1, PA, 3
  2, OR, 2
  </code></pre>
  
  <p>I then have a hasMany relation within the State Model:</p>
  
  <pre><code>class State extends Model
  {
      public function cities()
      {
          return $this-&gt;hasMany(City::class, 'state', 'name');
      }
  }
  </code></pre>
  
  <p>This relationship defines the 'state' column from the State Model as the foreign key, and the 'name' column from City as the local key.</p>
  
  <p>I am wondering if this relationship could be better. Is there a way that I could build the City Model with an attribute of 'state_id', and then have that match the State Model's 'id' attribute? Would this make for a performance increase for when I call <code>App\State::find(#)-&gt;cities</code>?</p>
  
  <p>Or, is there anything else I need to do to define 'state' as the foreign key for the State Model?</p>
  
  <p>Also, is there a simpler way of extracting the CSV file to multiple separate models with Eloquent, rather than a foreach loop through each record in the CSV?</p>
  
  <p>Thanks,</p>