簡體   English   中英

使用 Laravel 刀片進行分頁

[英]Pagination with Laravel Blade

我正在嘗試使用分頁返回數據。 當我將數據作為 paginate() 返回時,我收到一個錯誤: htmlspecialchars() expects parameter 1 to be string, array given

我的 controller:

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

刀:

            <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 這實際上引入了一個錯誤,它打破了 Tailwind 分頁開箱即用,理想情況下應該恢復它。

嘗試使用 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)

導致問題的行:

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

這是由於 Laravel 默認附帶resources/lang/en/pagination.php文件。 這個PR導致分頁語言文件返回的數組傳入__()方法,導致解析異常。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM