简体   繁体   中英

Pagination with Laravel Blade

I'm trying to return data with a pagination. When I'm returning the data as paginate() I receive an error: htmlspecialchars() expects parameter 1 to be string, array given

My controller:

$tickets = Ticket::where('company_id', Auth::user()->company_id)->paginate(3);

Blade:

            <table class="bg-white overflow-hidden table-auto w-full flex-row flex-no-wrap whitespace-nowrap">
            <tr>
                <th></th>
                <th class="bg-white px-4 py-2">Updated at</th>
                <th class="bg-white px-4 py-2">Case Title</th>
                <th class="bg-white px-4 py-2">Manager</th>
                <th class="bg-white px-4 py-2">Case ID</th>
                <th class="bg-white px-4 py-2">Remaining</th>
                <th class="bg-white px-4 py-2">Status</th>
            </tr>
            @foreach($tickets as $ticket)
            <tr class="bg-gray-100 text-center">
                <td class="px-2"><span class="text-blue-900 font-bold text-xs">
                        @if($ticket->isNew($ticket->created_at))
                        New
                        @endif
                    </span></td>
                <td class="px-4">{{ $ticket->updated_at }}</td>
                <td class="px-4 py-4">{{ $ticket->title }}</td>
                <td class="px-4 py-4">{{ $ticket->getAdmin->first_name }} {{ $ticket->getAdmin->last_name }}</td>
                <td class="px-4 py-4">{{ $ticket->id }}</td>
                <td class="px-4 py-4">
                    @php
                    $dueDate = \Carbon\Carbon::parse($ticket->end_date);
                    @endphp
                    @if($dueDate->isPast())
                    <span class="text-red-600">Overdue</span>
                    @else
                    {{ $ticket->remaining_date() }} Days
                    @endif
                </td>

                <td class="px-4 py-4">
                    @if($ticket->status == 1)
                    <span class="bg-yellow-500 font-semibold text-white p-2 rounded">Active</span>
                    @endif
                    @if($ticket->status == 2)
                    <span class="bg-blue-500 font-semibold text-white p-2 rounded">Closed</span>
                    @endif
                    @if($ticket->status == 3)
                    <span class="bg-red-800 font-semibold text-white p-2 rounded">Late</span>
                    @endif
                </td>
                </td>
            </tr>
            @endforeach
        </table>
        
        {{!! $tickets->links() !!}}

I don't get it why I receive the error and have tried to Google around it. Why is the error appear and what's the solution?

Update your version of Laravel. This was a breaking bug for 8.78. They tried changing Pagination Navigation for screen readers, but it broke certain translation settings, so it was reverted back. The details are at https://github.com/laravel/framework/pull/39928

@taylorotwell @xanderificnl This actually introduces a bug that breaks Tailwind pagination out of the box, and it should ideally be reverted.

When attempting to use Tailwind pagination, I'm seeing the following: htmlspecialchars(): Argument #1 ($string) must be of type string, array given (View: /var/www/html/vendor/laravel/framework/src/Illuminate/Pagination/resources/views/tailwind.blade.php)

The line causing the issue:

 <nav role="navigation" aria-label="{{ __('Pagination') }}" class="flex items-center justify-between">

This is due to Laravel shipping with a resources/lang/en/pagination.php file by default. This PR causes the array returned by the pagination language file to be passed into the __() method, which results in the parsing exception.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM