title: Accessing nested relationship with Laravel 4
body: <p>I'm having  trouble figuring out how to access a nested relationship within Laravel. The specific example I have is a Movie that has many entires in my Cast table which has one entry in my People table. These are my models:</p>
  
  <p><strong>MOVIE</strong></p>
  
  <pre><code>class Movie extends Eloquent {
  
      protected $primaryKey = 'movie_id';
      protected $table = 'movie';
  
      // Relationships
      public function cast()
      {
          return $this-&gt;hasMany('MovieCast', 'movie_id');
      }
  }
  </code></pre>
  
  <p><strong>MOVIECAST</strong></p>
  
  <pre><code>class MovieCast extends Eloquent {
  
      protected $table = 'movie_cast';
  
      public function person()
      {
          return $this-&gt;hasOne('Person', 'person_id');
      }
  
      public function netflix()
      {
          return $this-&gt;belongsTo('Movie', 'movie_id');
      }
  }
  </code></pre>
  
  <p><strong>PERSON</strong></p>
  
  <pre><code>class Person extends Eloquent {
  
      protected $primaryKey = 'person_id';
      protected $table = 'people';
  
      public function movieCast()
      {
          return $this-&gt;belongsTo('MovieCast', 'person_id');
      }
  }
  </code></pre>
  
  <p>In my controller I can access the cast (containing <code>person_id</code> and <code>role_id</code>) like so:</p>
  
  <pre><code>public function movie($id)
      {
          $movie = Movie::find($id);
          $cast = $movie-&gt;cast();
  
          return View::make('movie')-&gt;with(array(
              'movie' =&gt; $movie,
              'cast' =&gt; $cast
          ));
      }
  </code></pre>
  
  <p>...but I don't know how to access the corresponding <code>name</code> field in my <code>People</code> table.</p>
  
  <p><strong>EDIT 1:</strong></p>
  
  <p>Using the classes exactly as defined below in @msturdy's answer, with the controller method above I try to render the <code>person</code> names like so inside my view:</p>
  
  <pre><code>@foreach($cast-&gt;person as $cast_member)
          {{$cast_member-&gt;person-&gt;name}}
      @endforeach
  </code></pre>
  
  <p>Doing this i get the error:</p>
  
  <p><code>Undefined property: Illuminate\Database\Eloquent\Relations\HasMany::$person</code></p>
  
  <p><img src="https://i.stack.imgur.com/c0sqo.png" alt="enter image description here"></p>
  
  <p>I don't know if it makes a difference or not but I have no <code>id</code> field on my <code>People</code> table. <code>person_id</code> is the primary key.</p>