nickywan123

nickywan123

Member Since 2 Months Ago

Experience Points
5,820
Total
Experience

4,180 experience to go until the next level!

In case you were wondering, you earn Laracasts experience when you:

  • Complete a lesson — 100pts
  • Create a forum thread — 50pts
  • Reply to a thread — 10pts
  • Leave a reply that is liked — 50pts
  • Receive a "Best Reply" award — 500pts
Lessons Completed
0
Lessons
Completed
Best Reply Awards
0
Best Reply
Awards
  • start your engines Created with Sketch.

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • first-thousand Created with Sketch.

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • 1-year Created with Sketch.

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • 2-years Created with Sketch.

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • 3-years Created with Sketch.

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • 4-years Created with Sketch.

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • 5-years Created with Sketch.

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • school-in-session Created with Sketch.

    School In Session

    Earned when at least one Laracasts series has been fully completed.

  • welcome-newcomer Created with Sketch.

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • full-time-student Created with Sketch.

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • pay-it-forward Created with Sketch.

    Pay It Forward

    Earned once you receive your first "Best Reply" award on the Laracasts forum.

  • subscriber Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • evangelist Created with Sketch.

    Laracasts Evangelist

    Earned if you share a link to Laracasts on social media. Please email [email protected] with your username and post URL to be awarded this badge.

  • chatty-cathy Created with Sketch.

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • lara-veteran Created with Sketch.

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • 10k-strong Created with Sketch.

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • lara-master Created with Sketch.

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • laracasts-tutor Created with Sketch.

    Laracasts Tutor

    Earned once your "Best Reply" award count is 100 or more.

  • laracasts-sensei Created with Sketch.

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • top-50 Created with Sketch.

    Top 50

    Earned once your experience points ranks in the top 50 of all Laracasts users.

Level 2
5,820 XP
May
29
15 hours ago
Activity icon

Replied to How To Group Multiple Orders As A Single Entity?

@michaloravec He did explain to loop each page of what I want which works if I only make 1 order from 1 seller with items more than 5 items. If there's multiple sellers, then it's gonna treat each order as a new page.

Activity icon

Replied to How To Group Multiple Orders As A Single Entity?

Impossible to do what I want you mean?

Because of model relationship?

Would array_slice or array_chunk solve it?

I want to accomplish this issue without messing with the model.

Activity icon

Replied to How To Prevent Page-break In The Last Table?

Just never though of that, while I noticed the chunking of page is correct if the the items are from the same seller. My relationship is purchase has many orders. Each order has many items. So what my issue is explained in this thread, can you have a look and see why?

https://laracasts.com/discuss/channels/laravel/how-to-group-multiple-orders-as-a-single-entity

Activity icon

Replied to How To Prevent Page-break In The Last Table?

Can you explain behind the scenes?

I know $loop->iteration starts the loop from 1 to the last index.

Does that mean in the third page (11,12,....) and fourth page, it will also iterate correctly?

Activity icon

Replied to How To Prevent Page-break In The Last Table?

Okay it works but while you're here, how do I make the iteration in first column for next page to continue 6,7,..... instead of 1 again.

Activity icon

Started a new Conversation How To Prevent Page-break In The Last Table?

I am using a foreach paging to display table for each page. I added:

 <div style="page-break-before:always;">

before my end of loop to always start a new page after the table has five items. In my last page, the bottom of my table has some subtotal columns which should not "break" to the next page. How do I avoid it?

Code:

  @foreach($orders->items->chunk(5) as $page)
.......
.......
    <div class="row">
           
            <div class="col-xs-12 pl-1 pr-1 page">
                <div style="border: 1px solid #000; width: 100%; height: 625px;">
                    <table style="width: 100%; ">
                        <tr style="text-align: center; font-weight: 600;">
                            <td style="position: relative; font-size: 10pt; padding: 4px; border-bottom: 1px solid #000000; border-right: 1px solid #000000; width: 5%;">
                                <div style="position: absolute; top: 0; right: 0; margin-right: -1px; border-right: 1px solid #000000; height: 624px;"></div>
                                No.
                            </td>
                            <td style="position:relative; font-size: 10pt; padding: 4px; border-bottom: 1px solid #000000; border-right: 1px solid #000000; width: 12%;">
                                <div style="position: absolute; top: 0; right: 0; margin-right: -1px; border-right: 1px solid #000000; height: 624px;"></div>
                                Product Code
                            </td>
                            <td style="position: relative; font-size: 10pt; padding: 4px; border-bottom: 1px solid #000000; border-right: 1px solid #000000; width: 53%;">
                                <div style="position: absolute; top: 0; right: 0; margin-right: -1px; border-right: 1px solid #000000; height: 624px;"></div>
                                Description
                            </td>
                            <td style="position: relative; font-size: 10pt; padding: 4px; border-bottom: 1px solid #000000; border-right: 1px solid #000000; width: 6%">
                                <div style="position: absolute; top: 0; right: 0; margin-right: -1px; border-right: 1px solid #000000; height: 624px;"></div>
                                Quantity
                            </td>
                            <td style="position: relative; font-size: 10pt; padding: 4px; border-bottom: 1px solid #000000; border-right: 1px solid #000000; width: 12%;">
                                <div style="position: absolute; top: 0; right: 0; margin-right: -1px; border-right: 1px solid #000000; height: 624px;"></div>
                                Unit Price (RM)
                            </td>
                            <td style="font-size: 10pt; padding: 4px; border-bottom: 1px solid #000000; width: 12%;">Amount (RM)</td>
                        </tr>

                        <?php
                        $iterationNo = 0;
                        ?>
                       @foreach($page as $item)
                       
                        <tr style="font-size: 10pt;">
                            <td style="padding: 16px; text-align: center; vertical-align: top;">
                                <?php
                                $iterationNo = $iterationNo + 1;
                                ?>
                                {{ $iterationNo }}
                            </td>
                            <td style="padding: 16px; vertical-align: top;">
                                {{ $item->product->parentProduct->product_code }}
                            </td>
                            <td style="padding: 6px; vertical-align: top;">
                                <table>
                                    <tr style="font-size: 10pt;">
                                        <td style="padding: 4px; vertical-align: top;">
                                            <img src="{{ asset('storage/' . $item->product->parentProduct->images[0]->path . '/' . $item->product->parentProduct->images[0]->filename) }}" alt="{{ $item->product->parentProduct->name }}" style="width: 105px; height: 90px; border-radius: 10px;">
                                        </td>
                                        <td style="padding: 14px; vertical-align: top;">
                                            <p style="margin-bottom: 5px;">
                                                {{ $item->quantity }} x {{ $item->product->parentProduct->name }}
                                            </p>
                                            <p style="margin: 0;">
                                                @if(array_key_exists('product_color_name', $item->product_information))
                                                Color: {{ $item->product_information['product_color_name'] }}
                                                @endif
                                                @if(array_key_exists('product_size', $item->product_information))
                                                Color Temperature: {{ $item->product_information['product_size'] }}
                                                @endif
                                                @if(array_key_exists('product_temperature', $item->product_information))
                                                Color Temperature: {{ $item->product_information['product_temperature'] }}
                                                @endif
                                            </p>
                                        </td>
                                    </tr>
                                </table>
                            </td>
                            <td style="padding: 16px; text-align: center; vertical-align: top;">
                                {{ $item->quantity }}
                            </td>
                            <td style="padding: 16px; text-align: center; vertical-align: top;">
                                {{ $item->product->getDecimalPrice() }}
                            </td>
                            <td style="padding: 16px; text-align: center; vertical-align: top;">
                                {{ number_format(($item->subtotal_price / 100), 2) }}
                            </td>
                        </tr>
                        @endforeach
                    </table>
                   
                </div>
               
            </div>
            <div style="page-break-before:always;">
            @endforeach

 <div class="col-xs-12 pl-1 pr-1">
                <div style="width: 100%;">
                    <table style="width: 100%; font-size: 10pt;">
                        <tr>
                            <td style="padding: 4px; width: 5%;">

                            </td>
                            <td style="padding: 4px; width: 63%;">

                            </td>
                            <td style="padding: 4px; width: 20.2%">

                            </td>
                            <td style="border-left: 1px solid #000000; border-right: 1px solid #000000; padding: 4px; width: 13%;">

                            </td>
                        </tr>
                        <tr>
                            <td>

                            </td>
                            <td rowspan="6" style=" ">
                                <label for="textarea">Remarks:</label> <br>
                                <textarea name="remarks" id="" cols="70" rows="8">
                                </textarea>
                            </td>

                            <td style="padding: 6px;">
                                Subtotal
                            </td>
                            <td style="padding: 4px; border-bottom: 1px solid #000000; border-left: 1px solid #000000; border-right: 1px solid #000000;">
                                <?php
                                $subtotal = 0;

                                foreach ($order->items as $item) {
                                    $subtotal = $subtotal + $item->subtotal_price;
                                }

                                ?>
                                RM {{ number_format(($subtotal / 100), 2)}}
                            </td>
                        </tr>

                        <tr>
                            <td>

                            </td>
                            <td style="padding: 6px;">
                                Deliver Fee
                            </td>
                            <td style="padding: 4px; border-bottom: 1px solid #000000; border-left: 1px solid #000000; border-right: 1px solid #000000;">
                                <?php
                                $deliveryFee = 0;

                                foreach ($order->items as $item) {
                                    $deliveryFee = $deliveryFee + $item->delivery_fee;
                                }

                                ?>
                                RM {{ number_format(($deliveryFee / 100), 2) }}
                            </td>
                        </tr>

                        <tr>
                            <td>

                            </td>
                            <td style="padding: 6px;">
                                Installation Fee
                            </td>
                            <td style="padding: 4px; border-bottom: 1px solid #000000; border-left: 1px solid #000000; border-right: 1px solid #000000;">
                                <?php
                                $installationFee = 0;

                                foreach ($order->items as $item) {
                                    $installationFee = $installationFee + $item->installation_fee;
                                }

                                ?>
                                RM {{ number_format(($installationFee / 100), 2) }}
                            </td>
                        </tr>

                        <tr>
                            <td>

                            </td>
                            <td style="padding: 6px;">
                                Grand Total
                            </td>
                            <td style="padding: 4px; border-bottom: 1px solid #000000; border-left: 1px solid #000000; border-right: 1px solid #000000;">
                                <?php
                                $grandTotal = 0;

                                foreach ($order->items as $item) {
                                    $grandTotal = $grandTotal + $item->subtotal_price + $item->delivery_fee + $item->installation_fee;
                                }

                                ?>
                                RM {{ number_format(($grandTotal / 100), 2) }}
                            </td>
                        </tr>

                        <tr>
                            <td>

                            </td>
                            <td style="padding: 6px;">
                                Amount Paid
                            </td>
                            <td style="padding: 4px; border-bottom: 1px solid #000000; border-left: 1px solid #000000; border-right: 1px solid #000000;">
                                <?php
                                $grandTotal = 0;

                                foreach ($order->items as $item) {
                                    $grandTotal = $grandTotal + $item->subtotal_price + $item->delivery_fee + $item->installation_fee;
                                }

                                ?>
                                RM {{ number_format(($order->purchase->successfulPayment->amount / 100), 2) }}
                            </td>
                        </tr>

                        <tr>
                            <td>

                            </td>
                            <td style="padding: 6px;">
                                Balance Due
                            </td>
                            <td style="padding: 4px; border-bottom: 1px solid #000000; border-left: 1px solid #000000; border-right: 1px solid #000000;">
                                <?php
                                $balance = $grandTotal;
                                $balance = $order->purchase->successfulPayment->amount - $balance;
                                ?>
                                RM {{ number_format(($balance / 100) , 2)}}
                            </td>
                        </tr>
                    </table>
                </div>
            </div>
        </div>
Activity icon

Started a new Conversation How To Increment Counter In Next Page Without Resetting?

I output a list of items using chunk() on my snappy pdf table. Any items after 5 will be loop to a next page. However, in the next page, my counter starts from 1 again when it should be 6 onwards to continue.

Code:


                        <?php
                        $iterationNo = 1;
                        ?>
                        
                       
                        {{---Iterate each page--}}
                        @foreach ($page as $item)
                        <?php
                        $iterationNo = $iterationNo + 1;
                        
                         ?>
                        <tr style="font-size: 10pt;">  
                        
                            <td style="padding: 16px; text-align: center; vertical-align: top;">
                                
                                {{ $loop->iteration }}
                            </td>
                            <td style="padding: 16px; vertical-align: top;">
                                {{ $item->product->parentProduct->product_code }}
                            </td>
                            <td style="padding: 6px; vertical-align: top;">
                                <table>
                                    <tr style="font-size: 10pt;">
                                        <td style="padding: 4px; vertical-align: top;">
                                          
                                            <img src="{{ asset('storage/' . $item->product->parentProduct->images[0]->path . '/' . $item->product->parentProduct->images[0]->filename) }}" alt="{{ $item->product->parentProduct->name }}" style="width: 105px; height: 90px; border-radius: 10px;">
                                        </td>
                                        <td style="padding: 14px; vertical-align: top;">
                                            <p style="margin-bottom: 10px;">
                                                {{ $item->quantity }} x {{ $item->product->parentProduct->name }}
                                            </p>
                                            <p style="margin: 0;">
                                                @if(array_key_exists('product_color_name', $item->product_information))
                                                Color: {{ $item->product_information['product_color_name'] }}
                                                @endif
                                                @if(array_key_exists('product_size', $item->product_information))
                                                Color Temperature: {{ $item->product_information['product_size'] }}
                                                @endif
                                                @if(array_key_exists('product_temperature', $item->product_information))
                                                Color Temperature: {{ $item->product_information['product_temperature'] }}
                                                @endif
                                            </p>
                                        </td>
                                    </tr>
                                </table>
                            </td>
                            <td style="padding: 16px; text-align: center; vertical-align: top;">
                                {{ $item->quantity }}
                            </td>
                            <td style="padding: 16px; text-align: center; vertical-align: top;">
                                {{ $item->product->getDecimalPrice() }}
                            </td>
                            <td style="padding: 16px; text-align: center; vertical-align: top;">
                                {{ number_format(($item->subtotal_price / 100), 2) }}
                            </td>
                        </tr>
                       
                        @endforeach     
                    </table>
                    
                </div>    
            </div>
            <div style="page-break-before:always;">                   
            </div>
            

Though, use laravel counter $loop->iteration and it still the same issue.

$iterationNo starts again with 1 in next page. How do I make it start onwards with 6?

May
28
1 day ago
Activity icon

Started a new Conversation How To Group Multiple Orders As A Single Entity?

I am using snappy pdf to output a list of items bought by a user on a table in pdf. I want each table to limit only 5 items to display and the subsequent next 5 items will be on the next page with a new table and so on.

I thought of using chunk() to achieve this but my relationship model causes some issues. I have a purchase that can have many orders. Each order can have many items. So if I bought from:

Seller A: Item 1 Item 2

Seller B: Item 3

Seller C: Item 4 Item 5 Item 6

This means I will have 3 orders with 6 items. Though I want to display Item 1-5 in my first table but the chunk() loops each orders as separate, so items in seller A will be in first table and items in seller B will be in second table and so on (with a limit of 5).

My blade code:

  <div class="row ">
            <div class="col-xs-12 pl-1 pr-1">
                     
                <div style="border: 1px solid #000; width: 100%; height: 625px;">
                    @foreach($purchase->orders as $order)
                    @foreach($order->items->chunk(5) as $page)
                    <table style="width: 100%;">
                        <tr style="text-align: center; font-weight: 600;">
                            <td style="position: relative; font-size: 10pt; padding: 4px; border-bottom: 1px solid #000000; border-right: 1px solid #000000; width: 5%;">
                                <div style="position: absolute; top: 0; right: 0; margin-right: -1px; border-right: 1px solid #000000; height: 624px;"></div>
                                No.
                            </td>
                            <td style="position:relative; font-size: 10pt; padding: 4px; border-bottom: 1px solid #000000; border-right: 1px solid #000000; width: 12%;">
                                <div style="position: absolute; top: 0; right: 0; margin-right: -1px; border-right: 1px solid #000000; height: 624px;"></div>
                                Product Code
                            </td>
                            <td style="position: relative; font-size: 10pt; padding: 4px; border-bottom: 1px solid #000000; border-right: 1px solid #000000; width: 53%;">
                                <div style="position: absolute; top: 0; right: 0; margin-right: -1px; border-right: 1px solid #000000; height: 624px;"></div>
                                Description
                            </td>
                            <td style="position: relative; font-size: 10pt; padding: 4px; border-bottom: 1px solid #000000; border-right: 1px solid #000000; width: 6%">
                                <div style="position: absolute; top: 0; right: 0; margin-right: -1px; border-right: 1px solid #000000; height: 624px;"></div>
                                Quantity
                            </td>
                            <td style="position: relative; font-size: 10pt; padding: 4px; border-bottom: 1px solid #000000; border-right: 1px solid #000000; width: 12%;">
                                <div style="position: absolute; top: 0; right: 0; margin-right: -1px; border-right: 1px solid #000000; height: 624px;"></div>
                                Unit Price (RM)
                            </td>
                            <td style="font-size: 10pt; padding: 4px; border-bottom: 1px solid #000000; width: 12%;">Amount (RM)</td>
                        </tr>

                        <?php
                        $iterationNo = 0;
                        ?>
                        
                       
                        {{---Iterate each page--}}
                        @foreach ($page as $item)
                                   
                        <tr style="font-size: 10pt;">  
                        
                            <td style="padding: 16px; text-align: center; vertical-align: top;">
                                <?php
                                $iterationNo = $iterationNo + 1;
                                
                                ?>
                                {{ $iterationNo }}
                            </td>
                            <td style="padding: 16px; vertical-align: top;">
                                {{ $item->product->parentProduct->product_code }}
                            </td>
                            <td style="padding: 6px; vertical-align: top;">
                                <table>
                                    <tr style="font-size: 10pt;">
                                        <td style="padding: 4px; vertical-align: top;">
                                          
                                            <img src="{{ asset('storage/' . $item->product->parentProduct->images[0]->path . '/' . $item->product->parentProduct->images[0]->filename) }}" alt="{{ $item->product->parentProduct->name }}" style="width: 105px; height: 90px; border-radius: 10px;">
                                        </td>
                                        <td style="padding: 14px; vertical-align: top;">
                                            <p style="margin-bottom: 10px;">
                                                {{ $item->quantity }} x {{ $item->product->parentProduct->name }}
                                            </p>
                                            <p style="margin: 0;">
                                                @if(array_key_exists('product_color_name', $item->product_information))
                                                Color: {{ $item->product_information['product_color_name'] }}
                                                @endif
                                                @if(array_key_exists('product_size', $item->product_information))
                                                Color Temperature: {{ $item->product_information['product_size'] }}
                                                @endif
                                                @if(array_key_exists('product_temperature', $item->product_information))
                                                Color Temperature: {{ $item->product_information['product_temperature'] }}
                                                @endif
                                            </p>
                                        </td>
                                    </tr>
                                </table>
                            </td>
                            <td style="padding: 16px; text-align: center; vertical-align: top;">
                                {{ $item->quantity }}
                            </td>
                            <td style="padding: 16px; text-align: center; vertical-align: top;">
                                {{ $item->product->getDecimalPrice() }}
                            </td>
                            <td style="padding: 16px; text-align: center; vertical-align: top;">
                                {{ number_format(($item->subtotal_price / 100), 2) }}
                            </td>
                        </tr>
                       
                        @endforeach     
                       
                    </table>
                    @endforeach
                    @endforeach
                </div>
            </div>

How do I chunk items as one instead of orders?

Activity icon

Replied to Chunk Does Not Display The Correct Number Of Items

So after hours of trial and error and attempting at your solution, which was correct, I found a problem that lies more with my model relationship.

It display in the way that was designed oddly enough by the relationship model (not written by me),

For example:

Purchase 1: Order 1: Item A Order 2:Item B, Item C, Item D Order 3: Item E,Item F, Item G

Array : [ [A],[B,C,D],[E,F,G] ]

Output in PDF(based on chunk(5)):

Table 1:

Item A

Table 2(next page):

Item B, Item C, Item D

Table 3(next page): Item E, Item F, Item G

So I realize the relationship cause to incorrectly align them.

Activity icon

Replied to Chunk Does Not Display The Correct Number Of Items

I think you got a typo at

@foreach($page->items as $item)
Activity icon

Replied to Chunk Method Not Working For Blade

Because this involves snappy pdf. Not just output to normal HTML.

Activity icon

Replied to Chunk Does Not Display The Correct Number Of Items

In between here:

			@foreach($purchase->orders as $order)
                        @foreach($order->items->chunk(3) as $page)
                        <div> {{$page}}</div>
			{{---Iterate each page--}}
                        @foreach ($page->items as $item)
                            

you mean?

Though, I am aiming to output $item as it is the one that decides the output on number of items on the table.

Activity icon

Replied to How To Do Pagination In Snappy Pdf?

Sorry. I am really desperate with this issue. Also, I can't delete this thread at all.

Activity icon

Replied to How To Do Pagination In Snappy Pdf?

@michaloravec Where have you been :) ?

Been stuck on this problem for hours. LOL.

I did use $loop ->index but the iteration is not correct. Out of 6 items, it goes from [ 0,1,0,0,1,2].

Activity icon

Replied to Chunk Does Not Display The Correct Number Of Items

So I need to output the subsequent next page with everything I need?

Though, why is the chunk not limiting to 5 items via my for each loop?

Activity icon

Started a new Conversation How To Do Pagination In Snappy Pdf?

REMOVED

Activity icon

Replied to Chunk Does Not Display The Correct Number Of Items

So you are iterating an array of array from the usage of chunks. Okay that's much easier to understand.

Though based on your edited answer, I still get error:

Property [items] does not exist on this collection instance.

This is how my code looks like now:

  @foreach($purchase->orders as $order)
                        @foreach($order->items->chunk(3) as $page)
                        {{---Iterate each page--}}
                        @foreach ($page->items as $item)
                            
                      
                            
                        <tr style="font-size: 10pt;">  
                        
                            <td style="padding: 16px; text-align: center; vertical-align: top;">
                                <?php
                                $iterationNo = $iterationNo + 1;
                                
                                ?>
                                {{ $iterationNo }}
                            </td>
                            <td style="padding: 16px; vertical-align: top;">
                                {{ $item->product->parentProduct->product_code }}
                            </td>
                            <td style="padding: 6px; vertical-align: top;">
                                <table>
                                    <tr style="font-size: 10pt;">
                                        <td style="padding: 4px; vertical-align: top;">
                                          
                                            <img src="{{ asset('storage/' . $item->product->parentProduct->images[0]->path . '/' . $item->product->parentProduct->images[0]->filename) }}" alt="{{ $item->product->parentProduct->name }}" style="width: 105px; height: 90px; border-radius: 10px;">
                                        </td>
                                        <td style="padding: 14px; vertical-align: top;">
                                            <p style="margin-bottom: 10px;">
                                                {{ $item->quantity }} x {{ $item->product->parentProduct->name }}
                                            </p>
                                            <p style="margin: 0;">
                                                @if(array_key_exists('product_color_name', $item->product_information))
                                                Color: {{ $item->product_information['product_color_name'] }}
                                                @endif
                                                @if(array_key_exists('product_size', $item->product_information))
                                                Color Temperature: {{ $item->product_information['product_size'] }}
                                                @endif
                                                @if(array_key_exists('product_temperature', $item->product_information))
                                                Color Temperature: {{ $item->product_information['product_temperature'] }}
                                                @endif
                                            </p>
                                        </td>
                                    </tr>
                                </table>
                            </td>
                            <td style="padding: 16px; text-align: center; vertical-align: top;">
                                {{ $item->quantity }}
                            </td>
                            <td style="padding: 16px; text-align: center; vertical-align: top;">
                                {{ $item->product->getDecimalPrice() }}
                            </td>
                            <td style="padding: 16px; text-align: center; vertical-align: top;">
                                {{ number_format(($item->subtotal_price / 100), 2) }}
                            </td>
                        </tr>
                       
                        @endforeach     
                        @endforeach
                        @endforeach

Looks okay to me. My model relationship is correct. One purchase has many orders. One order has many items. Not sure why the chunk wouldn't limit it.

Tried using chunk(1), it will still display the total (6) items on the first table (page).

Activity icon

Replied to Chunk Does Not Display The Correct Number Of Items

Why do you have two for each loops for chunk onwards?

Your previous suggestion only shows 1 loop.

Edit:

Tested your solution, though I don't understand how you get $page->items as $item as it throws a Invalid argument supplied for foreach() error.

Activity icon

Replied to Chunk Method Not Working For Blade

Sorry if I wasn't being clear enough.

Yea I want to split it into pages, I figured using chunk() would solved this problem (correct me if I'm wrong).

I don't want to mess with the styling (borders,width,etc). So to clearly describe the output, imagine if I have the sixth item, it should be carried to the "next" page with all the table and trivial stuff intact while displaying the sixth item. Of course if there are 15 items, it should display five items per page with a total of 3 pages. Hope I am making sense.

Activity icon

Replied to How To Take First 5 Items In A Collection And The Next 5 For The Next Pages?

Also, why do you use :

class="{{ ($iteration_count%5) === 0 ? 'page-break-after: always;' : '' }}"

Isn't this for styling?

I am confused.

Edit:

Tested your solution, the outcome is still the same.

Activity icon

Replied to How To Take First 5 Items In A Collection And The Next 5 For The Next Pages?

What is the outcome of your code?

I tried using page-break-after before, it basically just shifts my stuff after the table to the next page though, I am trying to get the new(or next page) to be identical with the first page but showing the remaning nth items (6th item onwards) on the new page.

Is this something difficult to accomplish?

Activity icon

Started a new Conversation Chunk Does Not Display The Correct Number Of Items

I want to output 5 items on my table using chunk.

Code:

  @foreach($purchase->orders as $order)
                        @foreach($order->items->chunk(1) as $group)
                       
                        @foreach ($group as $item)
                            
                        <tr style="font-size: 10pt;">  
                        
                            <td style="padding: 16px; text-align: center; vertical-align: top;">
                                <?php
                                $iterationNo = $iterationNo + 1;
                                
                                ?>
                                {{ $iterationNo }}
                            </td>
                            <td style="padding: 16px; vertical-align: top;">
                                {{ $item->product->parentProduct->product_code }}
                            </td>
                            <td style="padding: 6px; vertical-align: top;">
                                <table>
                                    <tr style="font-size: 10pt;">
                                        <td style="padding: 4px; vertical-align: top;">
                                          
                                            <img src="{{ asset('storage/' . $item->product->parentProduct->images[0]->path . '/' . $item->product->parentProduct->images[0]->filename) }}" alt="{{ $item->product->parentProduct->name }}" style="width: 105px; height: 90px; border-radius: 10px;">
                                        </td>
                                        <td style="padding: 14px; vertical-align: top;">
                                            <p style="margin-bottom: 10px;">
                                                {{ $item->quantity }} x {{ $item->product->parentProduct->name }}
                                            </p>
                                            <p style="margin: 0;">
                                                @if(array_key_exists('product_color_name', $item->product_information))
                                                Color: {{ $item->product_information['product_color_name'] }}
                                                @endif
                                                @if(array_key_exists('product_size', $item->product_information))
                                                Color Temperature: {{ $item->product_information['product_size'] }}
                                                @endif
                                                @if(array_key_exists('product_temperature', $item->product_information))
                                                Color Temperature: {{ $item->product_information['product_temperature'] }}
                                                @endif
                                            </p>
                                        </td>
                                    </tr>
                                </table>
                            </td>
                            <td style="padding: 16px; text-align: center; vertical-align: top;">
                                {{ $item->quantity }}
                            </td>
                            <td style="padding: 16px; text-align: center; vertical-align: top;">
                                {{ $item->product->getDecimalPrice() }}
                            </td>
                            <td style="padding: 16px; text-align: center; vertical-align: top;">
                                {{ number_format(($item->subtotal_price / 100), 2) }}
                            </td>
                        </tr>
                        @endforeach     
                        @endforeach
                        @endforeach

There's six items displayed which is the total instead of 5. There's no error so I am not sure why it didn't display the 5 items. Did I make any mistake?

Activity icon

Replied to Chunk Method Not Working For Blade

@usmanbasharmal That was the same solution suggestion by @snapey. Apparently, it wouldn't work for my case.

Activity icon

Replied to Chunk Method Not Working For Blade

I attached a screenshot here to show you my issue.

https://ibb.co/TM7fQpd

As you can see, more than 5 items it will misaligned with the table. So I thought of outputting the sixth item onwards a new page (in SNAPPY PDF) while maintaining the exact same template with just the "new" table displaying the next nth items.

I don't know if this is a challenge outputting it on PDF.

Edit:

I actually made another thread regarding this issue:

https://laracasts.com/discuss/channels/laravel/possible-to-page-nth-elements-to-the-next-page-in-pdf

If you want to see the entire blade code, that's the link above.

I can imagine it would quite be a pain to do what I want.

Activity icon

Replied to Chunk Method Not Working For Blade

Your solution :

 		  @foreach($purchase->orders as $order)
                      @foreach($order->items->chunk(3) as $group)
                        @foreach ($group as $item)
                            
                                        
                        <tr style="font-size: 10pt;">
                            <td style="padding: 16px; text-align: center; vertical-align: top;">
                                <?php
                                $iterationNo = $iterationNo + 1;
                                // $page= array_chunk($order->items->toArray(),5);
                                // $chunks = $order->chunk(1);
                                // $chunks->toArray();
                                
                                ?>
                                {{ $iterationNo }}
                            </td>
                            <td style="padding: 16px; vertical-align: top;">
                                {{ $item->product->parentProduct->product_code }}
                            </td>
................
..............

Somehow still outputs all 6 items though, anything I did wrong?

Activity icon

Replied to Chunk Method Not Working For Blade

If my collection has say 10 different items. My chunk(5) shall take first 5 items and output them, how do I get the chunk 6th to 10th items for my next page?

Activity icon

Replied to How To Take First 5 Items In A Collection And The Next 5 For The Next Pages?

Yea I am aware that I defined a fixed height for my table which leads to the overlapping issue. Though, say I am insisting on getting the 6th and beyond items on the next page with everything else staying the same, would it be possible and how hard would it be?

I assume it would be a challenge considering I need to have the logo ,header and footer to remain for every "new" page for as long as the number of items is greater than 5.

Also, I am new to using snappy pdf so I am kinda blur when it comes to pagination or what you would call it.

Activity icon

Replied to Chunk Method Not Working For Blade

Pretty sure I verified they do as I tried removing the chunk() method and it returns correctly, so I was confused with this issue as well.

Activity icon

Replied to How To Take First 5 Items In A Collection And The Next 5 For The Next Pages?

Though if I set:

@foreach($purchase->orders as $order)
                        @foreach($order->items as $item)
                        @if($iterationNo<5)
                        ..........

It will only display first 5 items on first page.

Activity icon

Replied to How To Take First 5 Items In A Collection And The Next 5 For The Next Pages?

Please help I've been spending hours on this.

I want the 6th item to go to a new page. Think of the second page as the same as first page but with only the sixth item populating the table.

I tried chunk(),take(), array_chunk() but none of them worked.

Also, reason I declared variable $iterationNo in blade is because using $loop->iteration or index provided by laravel will not increment the result correctly, it goes like 0, 0, 1, 1.......

Activity icon

Replied to How To Take First 5 Items In A Collection And The Next 5 For The Next Pages?

I am trying to use chunk() or take() instead, like :

 @foreach($purchase->orders as $order)
                        @foreach($order->items->chunk(5) as $item)
.......
......

But it would give an error of course.

Activity icon

Replied to How To Take First 5 Items In A Collection And The Next 5 For The Next Pages?

I am using snappy pdf. I am facing the issue of displaying more than 5 items on the table where the next items just overlaps it. So I can't figure out a solution to solve this and I don't want to use page-break since I want the same page to be on the next page. While the sixth item displays on the next page table and so on.

Also, forgive the mess of my code as it was written by a colleague. I had no time for refactoring.

Activity icon

Started a new Conversation Chunk Method Not Working For Blade

I have to display my results as chunks of five in blade and this is my code:

   <?php
                        $iterationNo = 0;
                        ?>
                        @foreach($purchase->orders as $order)
                        @foreach($order->items->chunk(5) as $item)
                        
                        <tr style="font-size: 10pt;">
                            <td style="padding: 16px; text-align: center; vertical-align: top;">
                                <?php
                                $iterationNo = $iterationNo + 1;
                                
                                ?>
                                {{ $iterationNo }}
                            </td>
                            <td style="padding: 16px; vertical-align: top;">
                                {{ $item->product->parentProduct->product_code }}
                            </td>
                            <td style="padding: 6px; vertical-align: top;">
                                <table>
                                    <tr style="font-size: 10pt;">
                                        <td style="padding: 4px; vertical-align: top;">
                                            <img src="{{ asset('storage/' . $item->product->parentProduct->images[0]->path . '/' . $item->product->parentProduct->images[0]->filename) }}" alt="{{ $item->product->parentProduct->name }}" style="width: 105px; height: 90px; border-radius: 10px;">
                                        </td>
                                        <td style="padding: 14px; vertical-align: top;">
                                            <p style="margin-bottom: 10px;">
                                                {{ $item->quantity }} x {{ $item->product->parentProduct->name }}
                                            </p>
                                            <p style="margin: 0;">
                                                @if(array_key_exists('product_color_name', $item->product_information))
                                                Color: {{ $item->product_information['product_color_name'] }}
                                                @endif
                                                @if(array_key_exists('product_size', $item->product_information))
                                                Color Temperature: {{ $item->product_information['product_size'] }}
                                                @endif
                                                @if(array_key_exists('product_temperature', $item->product_information))
                                                Color Temperature: {{ $item->product_information['product_temperature'] }}
                                                @endif
                                            </p>
                                        </td>
                                    </tr>
                                </table>
                            </td>
                            <td style="padding: 16px; text-align: center; vertical-align: top;">
                                {{ $item->quantity }}
                            </td>
                            <td style="padding: 16px; text-align: center; vertical-align: top;">
                                {{ $item->product->getDecimalPrice() }}
                            </td>
                            <td style="padding: 16px; text-align: center; vertical-align: top;">
                                {{ number_format(($item->subtotal_price / 100), 2) }}
                            </td>
                        </tr>
                        
                        @endforeach
                        @endforeach
                    </table>

And it shows error:

Property [product] does not exist on this collection instance.

Not sure why this happens if I use chunk(). Tried replacing it with take() and it doesn't show the correct results either.

How do I resolve this?

May
27
2 days ago
Activity icon

Started a new Conversation How To Take First 5 Items In A Collection And The Next 5 For The Next Pages?

I have a PDF that outputs number of items bought in a table. The table can only output 5 items as the sixth item will overlap the alignment so I decided to make the next page same as the first page but outputs the sixth item onwards.

Code:

 <div class="row ">
            <div class="col-xs-12 pl-1 pr-1">
                <div style="border: 1px solid #000; width: 100%; height: 625px;">
                    <table style="width: 100%;">
                        <tr style="text-align: center; font-weight: 600;">
                            <td style="position: relative; font-size: 10pt; padding: 4px; border-bottom: 1px solid #000000; border-right: 1px solid #000000; width: 5%;">
                                <div style="position: absolute; top: 0; right: 0; margin-right: -1px; border-right: 1px solid #000000; height: 624px;"></div>
                                No.
                            </td>
                            <td style="position:relative; font-size: 10pt; padding: 4px; border-bottom: 1px solid #000000; border-right: 1px solid #000000; width: 12%;">
                                <div style="position: absolute; top: 0; right: 0; margin-right: -1px; border-right: 1px solid #000000; height: 624px;"></div>
                                Product Code
                            </td>
                            <td style="position: relative; font-size: 10pt; padding: 4px; border-bottom: 1px solid #000000; border-right: 1px solid #000000; width: 53%;">
                                <div style="position: absolute; top: 0; right: 0; margin-right: -1px; border-right: 1px solid #000000; height: 624px;"></div>
                                Description
                            </td>
                            <td style="position: relative; font-size: 10pt; padding: 4px; border-bottom: 1px solid #000000; border-right: 1px solid #000000; width: 6%">
                                <div style="position: absolute; top: 0; right: 0; margin-right: -1px; border-right: 1px solid #000000; height: 624px;"></div>
                                Quantity
                            </td>
                            <td style="position: relative; font-size: 10pt; padding: 4px; border-bottom: 1px solid #000000; border-right: 1px solid #000000; width: 12%;">
                                <div style="position: absolute; top: 0; right: 0; margin-right: -1px; border-right: 1px solid #000000; height: 624px;"></div>
                                Unit Price (RM)
                            </td>
                            <td style="font-size: 10pt; padding: 4px; border-bottom: 1px solid #000000; width: 12%;">Amount (RM)</td>
                        </tr>

                        <?php
                        $iterationNo = 0;
                        ?>
                        @foreach($purchase->orders as $order)
                        @foreach($order->items as $item)
                      
                        <tr style="font-size: 10pt;">
                            <td style="padding: 16px; text-align: center; vertical-align: top;">
                                <?php
                                $iterationNo = $iterationNo + 1;
                                ?>
                                {{ $iterationNo }}
                            </td>
                            <td style="padding: 16px; vertical-align: top;">
                                {{ $item->product->parentProduct->product_code }}
                            </td>
                            <td style="padding: 6px; vertical-align: top;">
                                <table>
                                    <tr style="font-size: 10pt;">
                                        <td style="padding: 4px; vertical-align: top;">
                                            <img src="{{ asset('storage/' . $item->product->parentProduct->images[0]->path . '/' . $item->product->parentProduct->images[0]->filename) }}" alt="{{ $item->product->parentProduct->name }}" style="width: 105px; height: 90px; border-radius: 10px;">
                                        </td>
                                        <td style="padding: 14px; vertical-align: top;">
                                            <p style="margin-bottom: 10px;">
                                                {{ $item->quantity }} x {{ $item->product->parentProduct->name }}
                                            </p>
                                            <p style="margin: 0;">
                                                @if(array_key_exists('product_color_name', $item->product_information))
                                                Color: {{ $item->product_information['product_color_name'] }}
                                                @endif
                                                @if(array_key_exists('product_size', $item->product_information))
                                                Color Temperature: {{ $item->product_information['product_size'] }}
                                                @endif
                                                @if(array_key_exists('product_temperature', $item->product_information))
                                                Color Temperature: {{ $item->product_information['product_temperature'] }}
                                                @endif
                                            </p>
                                        </td>
                                    </tr>
                                </table>
                            </td>
                            <td style="padding: 16px; text-align: center; vertical-align: top;">
                                {{ $item->quantity }}
                            </td>
                            <td style="padding: 16px; text-align: center; vertical-align: top;">
                                {{ $item->product->getDecimalPrice() }}
                            </td>
                            <td style="padding: 16px; text-align: center; vertical-align: top;">
                                {{ number_format(($item->subtotal_price / 100), 2) }}
                            </td>
                        </tr>
                        @endforeach
                        @endforeach
                    </table>
                </div>
            </div>

How do I make the "pagination" happen?

Activity icon

Replied to Background Image - How To Fit Screen Without Scrolling?

I changed to contain but still the same issue though.

Tried adding background-size: 100vw 100vh; but also same problem.

Activity icon

Started a new Conversation Background Image - How To Fit Screen Without Scrolling?

I added a background image on my blade file and I noticed I have to scroll a little bit vertically to see my footer. I already set my background image to cover and fit my screen but it still requires me to scroll.

Code:

@extends('layouts.shop.main-delhub')

@section('content')


{{-----Desktop layout----}}
<div class="wrapper delhub-digital-bg-img hidden-sm">

<div class="row">
    <div class="ml-5 col-4">
        <h1 style="color: whitesmoke; margin-top: 6rem;">DELHUB DIGITAL</h1>
    </div>
</div>
<div class="row mt-5">

    <div class="offset-1 col-6" style="font-size:13pt; color:whitesmoke;">
        <p>xxxxxxx.</p>
    </div>

    <div class="col-5">
        <div class="row">
            <div class="offset-1 col-5">
                <img src="{{asset('/storage/delhub-digital/2020.png')}}" alt="Bujishu-Project">
            </div>
            <div class="col-6 mt-5">
                <h1 style=" color:whitesmoke;">Our Projects</h1>
                <img class="mt-3" src="{{asset('/storage/delhub-digital/2021.png')}}" alt="2021-Project">
            </div>
        </div>
        <div class="row">
            <div class="offset-3 col-9">
                <img class="mt-3" src="{{asset('/storage/delhub-digital/2022.png')}}" alt="2022-Project">
            </div>
        </div>

    </div>
    
   

</div>

<footer>
    <div class="row pl-5 pr-2 footer-margin">
        <div class="col-6 col-md-3 text-center text-md-left ">
            <ul class="list-unstyled pr-2 pl-2">
                <li>
                    <p style="font-size: 1.1rem; color:white;">CONTACT US</p>
                    <p class="bujishu-white mb-1 " style="font-size: 0.9rem;">
                        1.26.5,
                        Menara Bangkok Bank
                        <br>
                        Kuala Lumpur, Malaysia
                    </p>
                </li>
                <li>
                    <p class="bujishu-white mb-1 " style="font-size: 0.9rem;">
                         Tel: 03-1234 5678
                    </p>
                </li>
               
            </ul>
        </div>
        <div class="offset-5 col-md-3 " style="padding-top:100px;">
            <h6 class="text-right mb-0 pt-1 pb-1 " style="color:black; font-size:13pt;">@ 2020 Bujishu. All Rights Reserved</h6>
        </div>
    </div>
    
    </footer>

</div>

Layout blade:

<body class="promo-page-background-color " >

    

    <main id="body-content-collapse-sidebar">
        <div id="app">
            @yield('content')
        </div>
    </main>

  
    
</body>


<style>
.delhub-digital-bg-img{
background-image: url(/images/delhub/delhub-digital-bg.jpg);
background-repeat: no-repeat;
background-position: fixed;
background-size: cover;
background-size:fixed;

}

If I add overflow:hidden, the wording in footer will not be partially visible.

How do I make it fit as one screen only without scrolling?

Activity icon

Replied to How To Make Webkit Support In All Other Browsers?

Not sure if your second link is a meant to be serious or just a joke lol.

Activity icon

Started a new Conversation How To Make Webkit Support In All Other Browsers?

I made a custom scrollbar styling using webkit. As far as I know it is only supported for Chrome browser.

Code:

.scrollbar::-webkit-scrollbar {
    width: 15px;
   
    
    
}

.scrollbar::-webkit-scrollbar-track {
    -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.3); 
    border-radius: 10px;
    
}

.scrollbar::-webkit-scrollbar-thumb {
    border-radius: 10px;
    
    -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.5); 
    background:#fbcc34; 
    
}

This means other browser will not see the CSS styling of my scrollbar. Is there any way to standardized it that it works in every browsers?

May
26
3 days ago
Activity icon

Started a new Conversation Text-capitalize Is Not Working?

I have an option box for selecting status like below:

 <div class="form-group col-md-6">
                                    <label for="gender">Gender</label>
                                    <select class="form-control" id="gender_id" name="gender_id">
                                        <option disabled selected value="default">Choose your gender..</option>
                                        @foreach($genders as $gender)
                                        <option class="text-capitalize" value="{{ $gender->id }}">{{ $gender->name }}</option>
                                        @endforeach
                                    </select>
                                </div>

When I select, say Male, the display on the box shows all lowercase male. I want it to be Male. My class text- capitalize is correct.

.text-capitalize {
  text-transform: capitalize !important;
}

Why is it not working?

Activity icon

Replied to Deleting Item Not Outputting The Correct Id

Oh and why do you use event.preventDefault() since my form method will return back() ? It essentially does the same thing.

Activity icon

Replied to Deleting Item Not Outputting The Correct Id

Right, but is this way really wrong to it or it's still fine?

Activity icon

Replied to Deleting Item Not Outputting The Correct Id

Since you use href to called the form (by masking), why not just use a form with submit button directly lol?

Activity icon

Replied to Deleting Item Not Outputting The Correct Id

Though, I thought to submit a form, you usually need a submit button to come with the request but I didn't know you can use anchor tag (href) to do the submit as well. A cool method indeed.

Activity icon

Replied to Deleting Item Not Outputting The Correct Id

Will it make a difference had it been outside the foreach?