I have implemented a laravel pagination in one of my project where pagination is working like a charm.
I have a requirement to display a pagination links on top of the table as well as the bottom of the table. Like this
{!! $entries->render() !!}
<table class="table table-responsive" id="entries-table">
<thead>
<tr>
<th>ID</th>
<th>Advisor name</th>
</tr>
</thead>
<tbody>
@forelse($entries as $entries)
<tr>
<td> {{ $entries->id }} </td>
<td> {{ $entries->name }} </td>
</tr>
@empty
<tr>
<td>
<p>No record found.</p>
</td>
</tr>
@endforelse
</tbody>
</table>
{!! $entries->render() !!}
When I try to use {!! $entries->render() !!}
one more time in the bottom of the table or anywhere in a same page, it throws me the below error.
ErrorException (E_ERROR) Call to undefined method App\Models\Entries::render()
here is my Controller code
public function index(Request $request)
{
$entries = Entries::orderBy('id', 'DESC')->paginate(15);
return view('entries.index')
->with('entries', $entries);
}
here I am dumping the varialbe $entries
in controller using dd($entries)
and this is what I am getting.
LengthAwarePaginator {#425 ▼
#total: 215
#lastPage: 15
#items: Collection {#436 ▼
#items: array:15 [▼
0 => entries {#437 ▶}
1 => entries {#438 ▶}
2 => entries {#439 ▶}
3 => entries {#440 ▶}
4 => entries {#441 ▶}
5 => entries {#442 ▶}
6 => entries {#443 ▶}
7 => entries {#444 ▶}
8 => entries {#445 ▶}
9 => entries {#446 ▶}
10 => entries {#447 ▶}
11 => entries {#448 ▶}
12 => entries {#449 ▶}
13 => entries {#450 ▶}
14 => entries {#451 ▶}
]
}
#perPage: 15
#currentPage: 1
#path: "https://samplesite.com/entries/11"
#query: []
#fragment: null
#pageName: "page"
+onEachSide: 3
#options: array:2 [▼
"path" => "https://samplesite.com/entries/11"
"pageName" => "page"
]
}
Check this Video i am sharing with you for better idea