title: Get ID from while looping
body: <p>I want to make an employee leave application, where when an employee submits leave request, his boss will immediately get a notification in the email</p>
  
  <p>My table in database like this</p>
  
  <pre><code>id |    name     |      email           | person_in_charge |
  1      Michael        michael.com                2
  2      Johan          johan.com                  4
  3      Lorem          lorem.com                  2
  4      Ipsum          ipsum.com                  5
  5      Dolor          dolor.com
  </code></pre>
  
  <p>I want to, when user id 1 sends an email, then the one who gets the email is user id 2, 4 and 5, because user id 2 is the boss of user id 1, and user id 4 is the boss of user id 2, and user id 5 is boss all of them.</p>
  
  <p>I've doing using while looping, but the result is the one who gets the email is user id 4 and 5, user id 2 not get the email</p>
  
  <p>Here's the code </p>
  
  <pre><code>$currentuserid = '1';
  
      $show= Users::where('id',$currentuserid)-&gt;first();
  
      if($show-&gt;pic_for!=null)
      {
          $pic_for = $tampil-&gt;pic_for;
  
          while($pic_for!=null)
          {
              $query = Users::where('id',$pic_for)-&gt;first();
  
              if($query-&gt;pic_for==null)
              {
                  break;
              }else
              {
                  $pic[]=$query-&gt;pic_for;
                  $pic_for = $query-&gt;pic_for;
  
              }
  
          }
          dd($pic);
  </code></pre>
  
  <p>Do you know where I missed ?</p>
  
  <p>Thank you</p>