title: Present related objects as strings on JSON responses on a Laravel REST API?
body: <p>I'm writing a REST API on Laravel and I'm taking advantage of polymorphic relationships. So many resources have tied <code>images</code>. When I create the response, using eager loading like this:</p>
  
  <pre><code>return User::with('image')-&gt;find($id);
  </code></pre>
  
  <p>I get something like this:</p>
  
  <pre><code>{
      id: 27,
      image: {
          id: 340,
          url: "https://amazonbucket.com/2lBqWzDme.jpg",
          created_at: "2015-01-28 17:21:17",
          updated_at: "2015-01-28 18:28:42",
      }
  }
  </code></pre>
  
  <p>Instead, I want it to be automatically output just the <code>url</code> as a <code>string</code> like this, so it's easier on the frontend:</p>
  
  <pre><code>{
      id: 27,
      image: "https://amazonbucket.com/2lBqWzDme.jpg"
  }
  </code></pre>
  
  <p>I tried to work with the <code>Image::toJson()</code> method but it didn't work. I Could use the <code>User::toJson()</code> method, but I'd had to do it on all the existing/upcoming instances that use <code>images</code>. Ideas?</p>