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.
In my RouteServiceProvider I have this:
public function boot(Router $router)
{
$router->bind('blog', function($id)
{
return Article::with('images')->findOrFail($id);
});
$router->bind('tags', function($name)
{
return Tag::where('name', $name)->firstOrFail();
});
parent::boot($router);
}
and in my view I have this {{ $article->images }}
which returns a collection, for example:
[{"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"}]
and it basically repeats the above for each article image in the foreach statement, except the id, article_id, path, etc. all changes.
{{ $article->images->path }}
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 {{ $article->images->path }}
without errors?
from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/1XscLA8
via IFTTT
Aucun commentaire:
Enregistrer un commentaire