0
<table>
    <thead>
    <tr style="font-size: 16px;">
        <th>approval_no</th>
        <th>pnr</th>
        <th>airline</th>
        <th>cost</th>
        <th>collected</th>
        <th>due_date</th>
        <th>time_limit</th>
        <th>notes</th>
        <th>approve_laststatus</th>
        <th>customer</th>
        <th>supplier</th>
        <th>created_by</th>
        <th>created_at</th>
        <th>Assignee</th>
        <th>Ticket Number</th>
        <th>Created By</th>
        <th>created_at</th>
        <th>EMD Number</th>
        <th>Created By</th>
        <th>created_at</th>
        <th>Invoice Number</th>
        <th>Created By</th>
        <th>created_at</th>
    </tr>
    </thead>
    <tbody>
    @foreach($approvals as $approval)
        <tr>
            <td>{{ $approval->approval_no }}</td>
            <td>{{ $approval->pnr }}</td>
            <td>{{ $approval->airline->airline }}</td>
            <td>{{ $approval->cost }}</td>
            <td>{{ $approval->collected }}</td>
            <td>{{ date("m/d/Y", strtotime($approval->due_date))}}</td>
            <td>{{ date("m/d/Y", strtotime($approval->time_limit))}}</td>
            <td>{{ $approval->notes }}</td>
            <td>{{ $approval->approve_laststatus}}</td>
            <td>{{ $approval->customer->customer_name}}</td>
            <td>{{ $approval->supplier->supplier_name}}</td>
            <td>{{ $approval->creator->first_name}}</td>
            <td>{{ date("m/d/Y", strtotime($approval->created_at))}}</td>
            <td>{{$approval->assignee}}</td>
        </tr>
        @if(!empty($approval->tickets))
            @foreach($approval->tickets as $ticket)
                    <tr>
                        <td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td>
                        <td>{{ $ticket->ticket_number }}</td>
                        <td>{{ $ticket->creator->first_name}}</td>
                        <td>{{ date("m/d/Y", strtotime($ticket->created_at))}}</td>
                    </tr>
            @endforeach
        @endif
        @if(!empty($approval->emd))
            @foreach($approval->emd as $emd)
                <tr>
                    <td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td>
                    <td>{{ $emd->emd_number }}</td>
                    <td>{{ $emd->creator->first_name}}</td>
                    <td>{{ date("m/d/Y", strtotime($emd->created_at))}}</td>
                </tr>
            @endforeach
        @endif
        @if(!empty($approval->invoices))
            @foreach($approval->invoices as $invoice)
                <tr>
                    <td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td>
                    <td>{{ $invoice->invoice_number }}</td>
                    <td>{{ $invoice->creator->first_name}}</td>
                    <td>{{ date("m/d/Y", strtotime($invoice->created_at))}}</td>
                </tr>
            @endforeach
        @endif
    @endforeach


    </tbody>
</table>


Im loading relationship data using laravel export to excel, This is the current code I'm using to show the data in the Excel sheet, I'm using laravel view to get the output. Attached is the output, the nested data print on one row down. Related data coloured in the same colour. How can I get the related data to start on the same row? enter image description here

1 Answer 1

0

To get the related data to start on the same row, you can modify the structure of your HTML table. Currently, you have separate rows for each related data (tickets, emd, invoices) within the main approval row. Instead, you can merge the cells for the related data into a single cell and use colspan to span multiple columns.

<table>
    <thead>
        <tr style="font-size: 16px;">
            <!-- Header columns -->
        </tr>
    </thead>
    <tbody>
        @foreach($approvals as $approval)
        <tr>
            <!-- Main approval data -->
        </tr>
        @if(!empty($approval->tickets))
        <tr>
            <td colspan="12">
                <table>
                    <thead>
                        <tr>
                            <!-- Header columns for tickets -->
                        </tr>
                    </thead>
                    <tbody>
                        @foreach($approval->tickets as $ticket)
                        <tr>
                            <!-- Ticket data -->
                        </tr>
                        @endforeach
                    </tbody>
                </table>
            </td>
        </tr>
        @endif
        @if(!empty($approval->emd))
        <tr>
            <td colspan="12">
                <table>
                    <thead>
                        <tr>
                            <!-- Header columns for emd -->
                        </tr>
                    </thead>
                    <tbody>
                        @foreach($approval->emd as $emd)
                        <tr>
                            <!-- EMD data -->
                        </tr>
                        @endforeach
                    </tbody>
                </table>
            </td>
        </tr>
        @endif
        @if(!empty($approval->invoices))
        <tr>
            <td colspan="12">
                <table>
                    <thead>
                        <tr>
                            <!-- Header columns for invoices -->
                        </tr>
                    </thead>
                    <tbody>
                        @foreach($approval->invoices as $invoice)
                        <tr>
                            <!-- Invoice data -->
                        </tr>
                        @endforeach
                    </tbody>
                </table>
            </td>
        </tr>
        @endif
        @endforeach
    </tbody>
</table>
Sign up to request clarification or add additional context in comments.

1 Comment

Hi Its coming in om same column no on the same row I wanted it in the same row

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.