christiangerdes's avatar

Advanced multiple paginations

Hi, I want to know how to treat every 5th row different in pagination. I have a $ads variable that keeps all ads with a active value of 1 in a pagination. Then I have another variable $business that keeps all ads with a active value of 2 in a pagination.

My problem is that I don't know how to specify that I want 4 normal ads listed and then 4 business ads and then 4 normal ads and so on.

public function category($category)
{
    $ads = $this->adRepo->getUsingCategory($category); // Returns LengthAwarePaginator
    $business = $this->adRepo->business($ads->count()); // Returns LengthAwarePaginator
    
    return view('search.category', compact('ads', 'business'));
}
@foreach($ads as $ad)
    // show 4 normal ads
    // After those show 4 business ads
@endforeach

How can this be done?

0 likes
2 replies
adrian.nuernberger's avatar

maybe i get you wrong, but don't you just look for modulo?

if ($i % 5 == 0)
{
    echo "5th row";
}
else
{
    echo "normal";
}

Please or to participate in this conversation.