title: hasMany and belongsTo in laravel
body: <p>I have a <em>Student</em> in the <code>users</code> table, <em>Parent</em> is in the same table, and that <em>Parent</em> is the parent of that <em>Student</em>.</p>
  
  <p>The <em>Student</em> has a <em>Schedule</em> in the <code>schedules</code> table.</p>
  
  <p>How I can write <code>hasMany</code> and <code>belongsTo</code> to get the proper relation like in following custom query which works fine:</p>
  
  <pre class="lang-php prettyprint-override"><code>$schedules = DB::table('users')
    -&gt;join('schedules', 'users.id', '=', 'schedules.studentID')
    -&gt;select('users.*', 'schedules.*', 'users.fname as fname', 'users.lname as lname')
    -&gt;where('users.parent_id',$request-&gt;id)
    -&gt;where('schedules.status','1')
    -&gt;where('schedules.status_dead','0')
    -&gt;whereIn('schedules.std_status',[1, 2])
    -&gt;get();
  </code></pre>
  
  <p>As shown in the image below:</p>
  
  <p><img src="https://i.stack.imgur.com/DUiqN.jpg" alt=""></p>