【发布时间】:2020-09-28 20:11:56
【问题描述】:
您好,我在使用 Paginator 时遇到问题,不知道如何使它工作。
这是我的 ReportsController:
public function index()
{
//Show all created reports
$reports = Reports::orderBy('created_at', 'desc')->paginate(15);
return view('reports.index', ['reports'=>compact('reports')])->with(['reports', $reports]);
}
这是 index.blade.php:
@foreach($reports as $report)
<tr>
<td scope="row"><a href="/reports/show">{{$report->id}}</td>
<td>{{$report->title}}</td>
<td>{{$report->category}}</td>
<td>{{$report->name}}</td>
<td>{{$report->created_at}}</td>
<td>{{$report->updated_at}}</td>
</tr>
@endforeach
【问题讨论】:
-
我认为我从未见过将数据传递到视图的所有方法都在一次尝试中使用。供参考:laravel.com/docs/8.x/views#passing-data-to-views 下面的答案是正确的,但请阅读文档;它们非常全面:)