title: Laravel Eloquent select from relationship
body: <p>I've been trying to get the hang of Laravel. I'm using Laravel 4.
  Right now I have two tables, a 'Products' table and a 'Images' table.
  A product can have many images and an image belongs to a product.</p>
  
  <p>So I have two models:</p>
  
  <pre><code>class Product extends Eloquent {
  
      public function images()
      {
          return $this-&gt;hasMany('Image');
      }
  
  }
  
  class Image extends Eloquent {
  
      protected $table = 'product_images';
  
      public function product()
      {
          return $this-&gt;belongsTo('Product');
      }
  
  }
  </code></pre>
  
  <p>Now I'm building the 'index' page of a resource, so I do Product::all() in the controller and send this to the view.</p>
  
  <p>In the view I do a foreach and loop over all products. But now I want to get an image to show with the product. But I can't seem to figure out how to get, for instance, the first image.</p>
  
  <p>When I do <code>$product-&gt;images</code> I get an object of all images related to the product.</p>
  
  <p>When I do <code>$product-&gt;images-&gt;url</code> I get an error (Undefined property 'url')</p>
  
  <p>I've tried <code>$product-&gt;images-&gt;first()-&gt;url</code> this also gives an error (Trying to get property of non-object)</p>
  
  <p>What am I doing wrong?</p>