I have one page which has two tabs, each one has it's pagination. It works correctly only when I click on tab, but when I click on previous or back page, it keeps returning to the first tab. this is my code on controller:
$entries = Entry::paginate(5,['*'],'entries')
->appends(request()->except('entries'));
$company_responses= CompanyResponse::paginate(5,['*'],'company_responses')
->appends(request()->except('company_responses'));
on view
{{$entries->appends(request()->except('entries'))->links()}}
{{$company_responses->appends(request()->except('company_responses'))->links()}}
tabs links
<div class="tab">
<button class="tablinks" onclick="openTab(event,'tab1')">الملاحظات</button>
<button class="tablinks" onclick="openTab(event,'tab2')">القيود</button>
</div>
I don't know what I need to do to make it works on previous or back.
Create a separate query for each tab and paginate the results
$tab1 = Model::where('column', 'value')->paginate(10);
$tab2 = Model::where('column', 'value')->paginate(15);
Results for each tab using the links() method on the pagination
<div class="tab-content">
<div class="tab-pane active" id="tab1">
@foreach($tab1 as $result)
{{ $result->column }}
@endforeach
{{ $tab1->links() }}
</div>
<div class="tab-pane" id="tab2">
@foreach($tab2 as $result)
{{ $result->column }}
@endforeach
{{ $tab2->links() }}
</div>
</div>
As suggested by Crisha: Create a separate query for each tab and paginate the results
$tab1 = Model::where('column', 'value')->paginate(10);
$tab2 = Model::where('column', 'value')->paginate(15);
I think you should be able to use this:
{{ $tab1->fragment('tab_id')->links() }}
{{ $tab2->fragment('tab_id')->links() }}
That should then add the tab # to the pagination links, you might need to add tab1 & tab2 where is has tab_id - as this is untested.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.