kickthemooon
3 years ago
102
6
General

ForEach with every 10th and 2nd changes

Posted 3 years ago by kickthemooon

So i am dealing with coupons that I need to print. I prepared the view and I am passing coupons to the view:

public function printSelected($ids){
        $couponIDs = explode(',', $ids);
        $selectedCoupons = Coupon::find($couponIDs);

        return view('admin.coupons.print')->with(compact('selectedCoupons'));
    }

Now I need to loop through them in a certain manner.

  1. every 10 coupons I need a new "page" block because 10 coupons fit into a page block
  2. every second coupon I need a new table row because 2 coupons or table data fits into one row
<div class="coupons">
<!-- every 10 coupons I need a new "page" block because 10 coupons fit into a page block -->
    <div class="page">
        <div class="subpage">
            <table>
        <!-- every second coupon I need a new table row because 2 coupons or table data fits into one row -->
                <tr>
                    <td>
                        <span class="coupon">{{ $coupon->code }}</span><br>
                        <hr>
                        <span class="name">{{ $coupon->user->name }}</span>
                    </td>
                    <td>
                        <span class="coupon">{{ $coupon->code }}</span><br>
                        <hr>
                        <span class="name">{{ $coupon->user->name }}</span>
                    </td>
                </tr>
            </table>
        </div>
    </div>
</div>

Any ideas? Help is appreciated.

Please sign in or create an account to participate in this conversation.