how to get the arrays values using their key in laravel blade pdf

20 views Asked by At

I have an array, and you want to iterate through its elements to create a table and then print the table in a PDF. the aim is to use localization for translating the array values, but i'm facing issues with getting the correct values in the PDF.

<?php
[
    'NIC' => 'ن.آئی.سی. نمبر',
    'Name' => 'نام',
    'Father Name' => 'والد کا نام',
    'Address' => 'پتہ',
    'Block #' => 'بلاک نمبر',
    'Page #' => 'صفحہ نمبر',
    'Series #' => 'سیریز نمبر',
    'House #' => 'گھر نمبر',
    'Polling Booth' => 'پولنگ بوتھ',
    'Polling Station' => 'پولنگ اسٹیشن',
];

Here is the blade file

<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Voter Information</title>
    <style>
        table {
            border-collapse: collapse;
            width: 100%;
        }

        th,
        td {
            border: 1px solid rgb(54, 53, 53);
            padding: 8px;
            text-align: left;
        }

        .col-name {
            width: 30%;
        }

        .col-value {
            width: 30%;
        }

        .img {
            width: 40%;
        }
    </style>
</head>

<body>
    <div class="row">
        <div class="col-lg-12">
            <table>
                <thead>
                    <tr>
                        <th colspan="1" style="text-align: center; vertical-align: middle;">
                            Party
                        </th>

                        <th colspan="2" style="text-align: center">Voter Information</th>

                    </tr>


                    @foreach ($data as $columnName => $columnValue)
                        <tr>

                            @if ($loop->first)
                                <th class="img" rowspan="{{ count($data) }}"
                                    style="text-align: center; vertical-align: middle;">
                           <img src="https://pppp.org.pk/website/wpcuploads/2020/11/hhuuh-1.png"
                                        style="width:100%" />
                                </th>
                            @endif

                            <th class="col-name">{{ trans("columns.$columnName") }}</th>
                            <td class="col-value">{{ $columnValue }}</td>
                        </tr>
                    @endforeach

                </thead>
            </table>
        </div>


    </div>


</body>

</html>

It seems like i'm encountering an issue with the localization of column names in your PDF. I want the column names to be displayed correctly, but they are appearing as columns.NIC and similar strings in the <th> elements.

enter image description here

0

There are 0 answers