分页 Laravel Blade

Pagination with Laravel Blade

我正在尝试 return 分页数据。当我 return 将数据作为 paginate() 时,我收到一个错误:htmlspecialchars() expects parameter 1 to be string, array given

我的控制器:

$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() !!}}

我不明白为什么我会收到错误并尝试 Google 绕过它。为什么会出现这个错误,如何解决?

更新您的 Laravel 版本。这是 8.78 的一个破坏性错误。他们尝试为屏幕阅读器更改 Pagination Navigation,但它破坏了某些翻译设置,所以它被还原了。详情在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.