I am working over a basic system where blogs retrieve the image from other database table but it shows the posts not the photos here is my controller:
$bloginfo=bloginfo::where('blog_name','=',$name)->first();
$blogposts=pageposts::where('p_id','=',$bloginfo->id)->orderBy('id','desc')->get();
foreach($blogposts as $posts){
$photoscount=pagephotos::where('b_id','=',$posts->id)->count();
$blogphotos=pagephotos::where('b_id','=',$posts->id)->get();
}
return View::make('myblog')
->with('bloginfo',$bloginfo)
->with('blogposts',$blogposts)
->with('blogphotos',$blogphotos)
->with('photoscount',$photoscount);
and here is my view:
@foreach($blogposts as $posts)
<div class="panel panel-default">
<div class="panel-body">
@if($photoscount==0)
{{ null }}
@elseif($photoscount==1)
//a bunch of code here
@else
//a bunch of code here
@endif
<h4><a href="">{{ $posts->title }}</a></h4>
<p>{{ $posts->description }}</p>
</div>
</div>
@endforeach