【问题标题】:Undefined property: Illuminate\Pagination\LengthAwarePaginator::$id. It says the problem is in my index未定义的属性:Illuminate\Pagination\LengthAwarePaginator::$id。它说问题出在我的索引中
【发布时间】: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 

【问题讨论】:

标签: php laravel laravel-7


【解决方案1】:
return view('reports.index', ['reports' => $reports]);
// or
return view('reports.index', compact('reports'));

你拥有的是这样的:

['reports' => ['reports' => $reports]]

如果你要使用with,那就是:

...->with('reports', $reports);
// or
...->with(['reports' => $reports]);

【讨论】:

  • 非常有帮助
  • @Strike 没问题,如果它对你有帮助,请随时投票:)
猜你喜欢
  • 2019-07-11
  • 2016-11-23
  • 2021-01-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-12-12
相关资源
最近更新 更多