title: How to get record from DB using id if no record for that id get increment that id and get record in laravel
body: <p>How to get record from DB using id and if no record for that id,increment that id and get record using incremented id in Laravel
  i.e: I`m passing id 50, if no record for id (50),then try for 51 .If not result found for 51 ,then 52...</p>
  
  <p>I tried to increase id like 50 + 1 that's not working for each case.
  if there are no id available ,then how to format this code:</p>
  
  <p>i.e</p>
  
  <p>Just i tell you questin clearly
  table structure like this</p>
  
  <pre><code>id    Personid
  
  50   1
  51   2
  52   null
  53   null
  54   null
  55   null
  56   null
  57   5
  58   6
  </code></pre>
  
  <p>if i pass id 52 means this will search id 52
  there is no value for 52 
  then it should search next id 53 thats also null ...
  so this should take id 57</p>
  
  <p>Laravel code:</p>
  
  <pre><code>public function getApplicantPopupDetails($id, $start = null) {
      $out = [];
      $array = [];
      $out = $this-&gt;initOut();
      $PersonId = $id;
  
      $applicant = DB::table('applicants')
                      -&gt;where('applicants.PersonId', '=', $PersonId)
                      -&gt;get(['Name','Address','Surname','country','Address','ContactNo','Email','created_at','imgUrl']);
      if($applicant-&gt;isEmpty()){
  
          if($start == 0){
              $ids = $PersonId - 1;
          } else {
              $ids = $PersonId + 1;
          }
          $array['main'] = $applicant;
          $this-&gt;getApplicantPopupDetails($ids,0);
      }
  
      $out['results'] = $array;
      return $out;
  }
  </code></pre>
  
  <p>I expected the above results without make any problem.</p>