简体   繁体   English

使用 Laravel 刀片进行分页

[英]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当我将数据作为 paginate() 返回时,我收到一个错误: htmlspecialchars() expects parameter 1 to be string, array given

My controller:我的 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.我不明白为什么我会收到错误并尝试使用 Google 来解决它。 Why is the error appear and what's the solution?为什么会出现错误,解决方法是什么?

Update your version of Laravel.更新您的 Laravel 版本。 This was a breaking bug for 8.78.这是 8.78 的一个重大错误。 They tried changing Pagination Navigation for screen readers, but it broke certain translation settings, so it was reverted back.他们尝试为屏幕阅读器更改Pagination Navigation ,但它破坏了某些翻译设置,所以它被恢复了。 The details are at https://github.com/laravel/framework/pull/39928详情在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. @taylorotwell @xanderificnl 这实际上引入了一个错误,它打破了 Tailwind 分页开箱即用,理想情况下应该恢复它。

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)尝试使用 Tailwind 分页时,我看到以下内容: 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.这是由于 Laravel 默认附带resources/lang/en/pagination.php文件。 This PR causes the array returned by the pagination language file to be passed into the __() method, which results in the parsing exception.这个PR导致分页语言文件返回的数组传入__()方法,导致解析异常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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