Thanks, but it won't work in my case.
foreach(range(1, 100) as $key => $value)
{
if(!($key % 3))
{
<div class="row">
<div class="col-md-4">
// laravel data goes here
</div>
</div>
}
}
So as you can see it will just print every col-md-4 in a new row, that's not what i needed. I need:
<div class="row">
<div class="col-md-4"></div>
<div class="col-md-4"></div>
<div class="col-md-4"></div>
</div>
Thanks again, but it won't work as i said above:
foreach(range(1, 12) as $key => $value)
{
if(!($key % 3))
{
echo "<div class='row'></div>";
}
echo '<div class="col-md-4">Laravel</div>';
}
it will output:
<div class='row'></div>
<div class="col-md-4">Laravel</div>
<div class="col-md-4">Laravel</div>
<div class="col-md-4">Laravel</div>
<div class="col-md-4">Laravel</div>
<div class='row'></div>
<div class="col-md-4">Laravel</div>
<div class="col-md-4">Laravel</div>
<div class="col-md-4">Laravel</div>
<div class="col-md-4">Laravel</div>
<div class='row'></div>
<div class="col-md-4">Laravel</div>
<div class="col-md-4">Laravel</div>
<div class="col-md-4">Laravel</div>
<div class="col-md-4">Laravel</div>
<div class='row'></div>
<div class="col-md-4">Laravel</div>
<div class="col-md-4">Laravel</div>
<div class="col-md-4">Laravel</div>
<div class="col-md-4">Laravel</div>
I need to wrap col-md-4's in to a row class. In your construction that won't happen.
Output of your code would be:
<div class='row'>
<div class="col-md-4">Laravel</div>
</div>
<div class='row'>
<div class="col-md-4">Laravel</div>
<div class="col-md-4">Laravel</div>
<div class="col-md-4">Laravel</div>
</div>
<div class='row'>
<div class="col-md-4">Laravel</div>
<div class="col-md-4">Laravel</div>
<div class="col-md-4">Laravel</div>
</div>
<div class='row'>
<div class="col-md-4">Laravel</div>
<div class="col-md-4">Laravel</div>
<div class="col-md-4">Laravel</div>
</div>
<div class='row'>
<div class="col-md-4">Laravel</div>
<div class="col-md-4">Laravel</div>
</div>
How to deal with the first row with single col-md? And it should output 4 rows instead of 5. Thanks for your help.
Ended up with such construction:
<div class="row">
@foreach(range(1, 12) as $key => $value)
@if(!($key % 3) and $key > 0)
</div>
<div class="row">
@endif
@foreach($category->articles()->orderBy('created_at', 'DESC')->paginate(12) as $article)
<div class="col-md-4">
<div class="video">
<a href="/article/{{ $article->slug }}"><img class="img-responsive" src="/imagecache/mainart/{{ $article->image }}" /></a>
<p>{{ strip_tags(str_limit($article->body, $limit = 90, $end = '...')) }}</p>
</div><!--video-->
</div><!--/col-md-4-->
@endforeach
@endforeach
</div>
but it outputs 4 rows and 12 col-md's in each row (it shoud be 3 col-md's in a single row, not 12)
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community