title: Sorting Laravel Collection via Array of ID's
body: <p>Is it possible to order a relationship collection using a separate array of ID's while still accessing through the relationship?</p>
  <p>The setup is <code>Checklist</code> has many <code>ChecklistItem</code>s and the desired order of the related items exists as a property <code>Checklist::$item_order</code>. It is just an array of numeric ID's in the user's desired order.
  :</p>
  <pre class="lang-php prettyprint-override"><code>class Checklist extends Model {
      protected $casts = ['item_order' =&gt; 'array'];
  
      public function items() {
          return $this-&gt;hasMany(ChecklistItem::class);
      }
  }
  class ChecklistItem extends Model {
      public function list() {
          return $this-&gt;belongsTo(Checklist::class);
      }
  }
  </code></pre>
  <p>I access this relationship the normal way:</p>
  <pre class="lang-php prettyprint-override"><code>$list = Checklist::find(1234);
  
  foreach ($list-&gt;items as $item) {
      // More Code Here
  }
  </code></pre>
  <p>Is there a feasible way to order <code>$list-&gt;items</code> based on the values in the <code>$list-&gt;item_order</code> array?</p>
  <p>(I can't just add an 'order' column to the 'item' table, b/c the order changes for each 'list'.)</p>