未定义 属性:Illuminate\Pagination\LengthAwarePaginator::$id。它说问题出在我的索引中

Undefined property: Illuminate\Pagination\LengthAwarePaginator::$id. It says the problem is in my index

您好,我的分页有问题,不知道如何解决。

这是我的报表控制器:

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]);