php - 未定义的属性:Illuminate\Pagination\LengthAwarePaginator::$id。它说问题出在我的索引中
问题描述
您好,我对 Paginator 有疑问,不知道如何使它工作。
这是我的报告控制器:
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
解决方案
return view('reports.index', ['reports' => $reports]);
// or
return view('reports.index', compact('reports'));
你有的是这样的:
['reports' => ['reports' => $reports]]
如果您要使用with
它将是:
...->with('reports', $reports);
// or
...->with(['reports' => $reports]);
推荐阅读
- python - Python中的txt文件中的if语句?
- sql - 在 SELECT 中更改 * 以显示所有列
- json - 在 Swift 中安全地访问具有任意键和值结构的 JSON 字典?
- python - 使用“时间”库在 python 中到 gmt 和从 gmt 返回到秒的秒数
- assembly - MOV EDX,[EBX + 8*EAX + 4]中使用的寻址方式是什么?
- design-patterns - F# 函数式回调
- python - 为不在另一个字典中的值过滤字典
- r - 如何在循环中保存多个ggplot图表以使用grid.arrange
- elasticsearch - Elasticsearch 建议评分不适用于模糊搜索
- shell - 将字符串中的单词提取到 shell 变量中