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 >
<button onclick="openTab(event,'tab1')">الملاحظات</button>
<button onclick="openTab(event,'tab2')">القيود</button>
</div>
I don't know what I need to do to make it works on previous or back.
CodePudding user response:
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 >
<div id="tab1">
@foreach($tab1 as $result)
{{ $result->column }}
@endforeach
{{ $tab1->links() }}
</div>
<div id="tab2">
@foreach($tab2 as $result)
{{ $result->column }}
@endforeach
{{ $tab2->links() }}
</div>
</div>
CodePudding user response:
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.