首页 > 解决方案 > Laravel 5.7 简单分页

问题描述

在我们的应用程序中,我们有称为报告的模块,在此报告中将向您显示模块的摘要。

例子

General Journal Report - in this report will show you the summarize of the general journal module.

现在在我们的报告中需要实现分页,在查询生成器中应用分页时遇到问题。

控制器

$general_journals                   = GeneralJournalReportModel::getGeneralJournals();
$data['defined_gj']              = GeneralJournalReportItemsController::getDefinedGJById($general_journals);

我获取所有常规日志记录并将其存储在变量 general_journals 中,然后我将其传递给另一个控制器以执行其他操作(例如在列为空时进行一些错误处理)。

模型

public static function getGeneralJournals()
{
            return DB::table('general_journals as gj')
                ->select('gj.id as id',
                        'gj.number as number',
                        'gj.posting_date as posting_date',
                        'gj.remarks as remarks',
                        'gj.document_reference as document_reference',
                        'gji.debit_amount as debit_amount',
                        'gji.credit_amount as credit_amount')
            ->leftJoin('general_journal_items as gji', 'gj.id', '=', 'gji.general_journal_id')
            ->where('gj.company_id', Auth::user()->company_id)
            ->where('gj.approval_status', 3)
            ->orderBy('gj.id', 'desc')
            ->simplePaginate(5);
}

看法

<div class="row">
<div class="col-md-12 col-sm-12 col-xs-12 col-lg-12">
    <div class="table-responsive">
        <table class="table table-striped table-bordered table-hover general-journal-report-table" id="gj-report">
            <thead class="thead-global">
                <tr>
                    <th id="pj_sequence">Sequence No.</th>
                    <th id="pj_date">Posting Date</th>
                    <th id="pj_op">Transaction No.</th>
                    <th id="4">Document Reference</th>
                    <th id="5">Remarks</th>  
                    <th id="6">Amount Due</th>
                </tr>
            </thead>
            <tbody class="general-journal-report-details">
                @if($defined_gj)
                <?php $counter = 0; ;?>
                <?php $total_debit = 0; ?>
                @foreach($defined_gj as $key => $value)
                    <?php $counter++;?>
                    <?php $total_debit += $value->debit ;?>
                    <tr>
                        <td class="pj_sequence">{{$counter}}</td>
                        <td class="pj_date">{{$value->posting_date}}</td>
                        <td class="pj_op">{!! $value->number !!}</td>
                        <td>{{$value->doc_ref}}</td>
                        <td>{{$value->remarks}}</td>
                        @if($value->debit == '0')
                        <td></td>
                        @else
                        <td align="right"> {{number_format($value->debit,2)}}</td>
                        @endif
                    </tr>
                @endforeach
                    <tr>
                        <td><b>Total</b></td>
                        <td></td>
                        <td></td>
                        <td></td>
                        <td></td>
                        <td align="right"> {{number_format($total_debit)}}</td>
                    </tr>
                @endif
            </tbody>
        </table>
    </div>
    {{ $general_journals->links() }}
</div>

当我使用 links() 我的按钮没有任何类。

问题:如何在链接按钮上放置一些类?

注意:我试过这个 {{ $general_journals->links() }} 但它只适用于上一个按钮(我还想在下一个按钮中应用该类)

标签: laravelpaginationlaravel-5.7

解决方案


如果您想自定义分页视图,可以点击此链接https://laravel.com/docs/5.7/pagination#customizing-the-pagination-view


推荐阅读