title: Laravel 5: Article hasMany Image, Image belongsTo Article. Getting a collection back
body: <p>When I create an article, I can attach one image to it, which acts as the thumbnail. Everything works properly in that the image gets uploaded to the img directory, the image path gets added to the images table, and the article_id in the images table relates to the id of the article being created.</p>
  
  <p>In my RouteServiceProvider I have this:</p>
  
  <pre><code>public function boot(Router $router)
  {
      $router-&gt;bind('blog', function($id)
      {
          return Article::with('images')-&gt;findOrFail($id);
      });
  
      $router-&gt;bind('tags', function($name)
      {
          return Tag::where('name', $name)-&gt;firstOrFail();
      });
  
      parent::boot($router);
  }
  </code></pre>
  
  <p>and in my view I have:</p>
  
  <pre><code>@foreach ($articles as $article)
      &lt;h2&gt;&lt;a href="/blog/{{ $article-&gt;id }}"&gt;{{ $article-&gt;title }}&lt;/a&gt;&lt;/h2&gt;
  
      &lt;p&gt;{{ $article-&gt;body }}&lt;/p&gt;
  
      &lt;small&gt;Posted on {{ date('F d, Y', strtotime($article-&gt;created_at)) }} by {{ $article-&gt;user-&gt;name }}&lt;/small&gt;
  
      &lt;img src="{{ $article-&gt;images }}"&gt;
  @endforeach
  </code></pre>
  
  <p><code>{{ $article-&gt;images }}</code> returns a collection, for example:</p>
  
  <pre><code>[{"id":17,"path":"img\/image2.jpg.jpg","article_id":49,"created_at":"2015-10-25 01:57:49","updated_at":"2015-10-25 01:57:49"}]
  </code></pre>
  
  <p>and it basically repeats the above for each article image in the foreach statement, except the id, article_id, path, etc. all changes.</p>
  
  <p><code>{{ $article-&gt;images-&gt;path }}</code> returns an error "Trying to get property of non-object". How can I write the code in my routeserviceprovider so that it gets just one image instead of a collection, so I can then use <code>{{ $article-&gt;images-&gt;path }}</code> without errors?</p>