title: Managing relationships in Laravel, adhering to the repository pattern
body: <p>While creating an app in Laravel 4 after reading T. Otwell's book on good design patterns in Laravel I found myself creating repositories for every table on the application.</p>
  
  <p>I ended up with the following table structure:</p>
  
  <ul>
  <li>Students: id, name</li>
  <li>Courses: id, name, teacher_id</li>
  <li>Teachers: id, name</li>
  <li>Assignments: id, name, course_id</li>
  <li>Scores (acts as a pivot between students and assignments): student_id, assignment_id, scores</li>
  </ul>
  
  <p>I have repository classes with find, create, update and delete methods for all of these tables. Each repository has an Eloquent model which interacts with the database. Relationships are defined in the model per Laravel's documentation: <a href="http://laravel.com/docs/eloquent#relationships" rel="noreferrer">http://laravel.com/docs/eloquent#relationships</a>.</p>
  
  <p>When creating a new course, all I do is calling the create method on the Course Repository. That course has assignments, so when creating one, I also want to create an entry in the score's table for each student in the course. I do this through the Assignment Repository. This implies the assignment repository communicates with two Eloquent models, with the Assignment and Student model.</p>
  
  <p>My question is: as this app will probably grow in size and more relationships will be introduced, is it good practice to communicate with different Eloquent models in repositories or should this be done using other repositories instead (I mean calling other repositories from the Assignment repository) or should it be done in the Eloquent models all together?</p>
  
  <p>Also, is it good practice to use the scores table as a pivot between assignments and students or should it be done somewhere else?</p>