title: Autoincrement column with conditions
body: <p>I would like to implement an order column (that will be used for determining hierarchy for the entities, both in backend and frontend). Is there a nice way to do this on the migration level?</p>
  <p>So that when a new model is saved, the highest number of the order column will be found - but only for the models that share shop_id. So if I add models like this:</p>
  <pre><code>// First model should get order = 1
      $priceExceptionA = new PriceException();
      $priceExceptionA-&gt;shop_id = 1;
      $priceExceptionA-&gt;amount = 100;
      $priceExceptionA-&gt;save();
  
  // Second model should get order = 2
      $priceExceptionB = new PriceException();
      $priceExceptionB-&gt;shop_id = 1;
      $priceExceptionB-&gt;amount = 100;
      $priceExceptionB-&gt;save();
  </code></pre>
  <p>I would like to find a way to implement this behavior already through the migration:</p>
  <pre><code>public function up()
  {
      Schema::create('price_exceptions', function (Blueprint $table) {
          $table-&gt;id();
          $table-&gt;integer('shop_id')-&gt;unsigned();
          $table-&gt;integer('amount')-&gt;nullable();
  
          // Find the highest order value for rows with the same shop_id and increment this by one
          $table-&gt;integer('order')-&gt;default(////)
  
          $table-&gt;timestamps();
          $table-&gt;softDeletes();
  
          $table-&gt;foreign('shop_id')-&gt;references('id')-&gt;on('shops')-&gt;onDelete('cascade');
      });
  }
  </code></pre>