title: Generate number in form (Year/Month/Type/Number) - Laravel/PHP
body: <p>I need add variable to form that will return number.</p>
  
  <p>My current code in controller.</p>
  
  <pre><code>    /*Generate number*/
      $query = Certificate::latest()-&gt;first(); //get last query
      $ex = explode('/', $query-&gt;number); //explode last number from DB
      $type = strtoupper(Request::segment(3)); //get type from url
  
      if(empty($query-&gt;number)) {
          $number = '1';
          $nextNumber = date('Y/m').'/'.$type.'/'.$number;
      } else {
          $number = $ex[3]+1;
          $nextNumber = date('Y/m').'/'.$type.'/'.$number;
      }
  </code></pre>
  
  <p>My current code in template.</p>
  
  <pre><code>{!! Form::text('number', $nextNumber, ['class'=&gt;'form-control', 'required']) !!}
  </code></pre>
  
  <p>My code return number YEAR/MONTH/TYPE/NUMBER - <a href="https://i.stack.imgur.com/0gy9V.jpg" rel="nofollow noreferrer">Screenshot in view</a></p>
  
  <p><em>Now it does not work as it should</em></p>
  
  <ul>
  <li>2018/07/WK/6</li>
  <li>2018/07/WK/7</li>
  <li>2018/07/S/8</li>
  <li>2018/07/WK/9</li>
  <li>2018/07/WK/10</li>
  <li>2018/07/S/11</li>
  <li>2018/07/PT/12 ... 13,14,15,16,17,18 ++ [...]</li>
  </ul>
  
  <p>I need reset number for TYPE and new month.</p>
  
  <p><em>Please see an example of an action:</em></p>
  
  <ul>
  <li>2018/07/WK/1</li>
  <li>2018/07/WK/2</li>
  <li>2018/07/S/1</li>
  <li>2018/07/WK/3</li>
  <li>2018/07/WK/4</li>
  <li>2018/07/S/2</li>
  <li>2018/07/PT/1</li>
  </ul>
  
  <p><em>Example in the new month:</em></p>
  
  <ul>
  <li>2018/08/WK/1</li>
  <li>2018/08/S/1</li>
  <li>2018/08/PT/1</li>
  <li>2018/08/WK/2</li>
  <li>2018/08/WK/3</li>
  <li>2018/08/S/2</li>
  <li>2018/08/PT/2</li>
  </ul>
  
  <p>I will be very grateful if someone leads me to a solution.</p>
  
  <p>Best regards :)</p>