title: How to transform eloquent relation object?
body: <p>We have following models -</p>
  
  <p><strong>Post</strong></p>
  
  <pre><code>----------------------------------------------
  | id | title | text | creator | status | etc |
  ----------------------------------------------
  |    |       |      |         |        |     |
  ----------------------------------------------
  
  creator -&gt; belongsTo User
  
  group -&gt; belongsTo group
  </code></pre>
  
  <p><strong>User</strong></p>
  
  <pre><code>posts -&gt; hasMany Posts
  
  avatar -&gt; hasOne Media
  </code></pre>
  
  <p><strong>Media</strong></p>
  
  <pre><code>user -&gt; belongsTo User
  </code></pre>
  
  <p><strong>Group</strong></p>
  
  <pre><code>post - belongsTo Post
  </code></pre>
  
  <p>When I fetch posts using eloquent I can use transform function to transform post attributes but unable to transform relations in the Post collections.</p>
  
  <pre><code>$posts = Post::where('status', 'active')
              -&gt;with(['creator.avatar','group'])
              -&gt;get();
  
  $posts-&gt;transform(function($post) {
      $post-&gt;title = 'Transformed'; // works
      $post-&gt;creator-&gt;avatar = ['path'=&gt;'/avatar/','file_name'=&gt;'a.png']; // does not work
  });
  </code></pre>