title: Eloquent attaching a many to many results in Trying to get property of non-object
body: <p>In my Lumen project I use a many to many relationship like this:</p>
  
  <pre><code>class Item{
      protected $appends = ['order'];
  
      public getOrderAttribute(){
        return $this-&gt;pivot-&gt;order;
      }
      public function collections(){
       return $this-&gt;belongsToMany(Collection)-&gt;withTimestamps()-&gt;withPivot('order');
      }
  }
  </code></pre>
  
  <p>and then in the collection</p>
  
  <pre><code>class Collection{
      public function items(){
       return $this-&gt;belongsToMany(Item)-&gt;withTimestamps()-&gt;withPivot('order')';
      }
  }
  </code></pre>
  
  <p>then I try to insert a new item in a collection like this:</p>
  
  <pre><code>addItem(Request $req, $id){ &lt;- is for collection
   $item = new Item();
   $item-&gt;save();
  
   $collection = Collection::findOrFail($id);
   $collection-&gt;items()-&gt;attach($item, ['order' =&gt; $req-&gt;input('order')]);
  return $item;
  </code></pre>
  
  <p>this result in <code>Trying to get property of non-object</code></p>
  
  <p>The data gets stored in the database succesfully and correctly.
  I have tried switching up the attach on collections() and on items() but that doenst change anything.
  I have tried to renew the item value like this: <code>Item::findOrFail($item-&gt;id)</code>
  still results in the same error.
  Abd when I refresh the page I get the correct data.</p>