title: Laravel change every model in collection
body: <p>I have a collection of Items. Now, before I am sending it though my api, I want to change a value of the model (but I don't want to update my model in the database).</p>
  
  <p>Now I want to loop though my collection and return it as json, but I am getting <code>invalid Payload</code>.</p>
  
  <p>Here is the code I perform:</p>
  
  <pre><code>$trainees = Trainee::select();
          if(!$request-&gt;user()-&gt;hasPermission('read-trainees')) {
              $trainees-&gt;where('status', 1)-&gt;where('visible', 1);
          } else {
              $trainees-&gt;with(array('user'=&gt;function($query){
                  $query-&gt;select('id','firstname', 'lastname');
              }));
              $trainees-&gt;select('user_id');
          }
          $trainees-&gt;select('interested_jobs', 'graduation');
          $trainees = $trainees-&gt;get();
          return $trainees
              -&gt;map(function ($item) {
                  $item-&gt;id = encrypt($item-&gt;id);
                  return $item;
              })
              -&gt;toJson();
  </code></pre>