title: Dependencies between School, Student and Lesson models
body: <p>I have a School model that has many Student models who attend to multiple Lesson models, I also have a controller for each one.</p>
  
  <p>I need the ability to access the school type (large, small, etc...), whether I am in the Student, Lesson or School controller.</p>
  
  <p>Would this approach be correct in a strict OOP world?</p>
  
  <pre class="lang-php prettyprint-override"><code>// School model
  class School
  {
      ...
  
      public getSchoolType()
      {
          return $this-&gt;schoolType;
      {
  
  }
  
  // Student model
  class Student
  {
      ...
  
      public school()
      {
          return $this-&gt;school;
      {
  
  }
  
  // Lesson model
  class Lesson
  {
      ...
  
      public student()
      {
          return $this-&gt;student;
      {
  
  }
  
  // Student controller 
  class StudentController
  {
      public function show(Student $student)
      {
          $schoolType = $student-&gt;school-&gt;schoolType;
          return view('students', array($schoolType));
      }
  }
  
  // Lesson controller 
  class LessonController
  {
      public function show(Lesson $lesson)
      {
          $schoolType = $lesson-&gt;student-&gt;school-&gt;schoolType;
          return view('lessons', array($schoolType));
      }
  }
  </code></pre>
  
  <p>If lessons relate to students in a Many-to-Many way, how do I get the schoolType within the Lesson controller if there is no students attending that Lesson?</p>
  
  <p>My point is, should I actually get the schoolType through the Student model like <code>$lesson-&gt;school-&gt;schoolType</code> or it should be more like <code>$lesson-&gt;student-&gt;school-&gt;schoolType</code>, so lessons simply don't relate directly to students?</p>