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

2.1k views Asked by At

Hello I have a problem with Paginator dont know how I can make it work.

This is my 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]);
    }

And this is the 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 
1

There are 1 answers

2
lagbox On BEST ANSWER
return view('reports.index', ['reports' => $reports]);
// or
return view('reports.index', compact('reports'));

What you had was this:

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

If you were going to use with it would be:

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