控制器
public function getSearch(Request $request)
{
$search = $request->input('search');
$clients = Client::search($search)
->paginate(5);
$bankings = Banking::search($search)
->paginate(5);
return view('search/search',compact(['clients','bankings']));
}
查看
@extends('layouts.master')
@section('content')
<div class="content">
<div class="row search">
<div class="col-xs-12">
<div class="box" >
<div class="box-body" >
<table class="table table-bordered table-hover" id="clients">
<thead>
<th>Customer Code</th>
<th>Surname</th>
<th>Name</th>
<th>Company Name</th>
<th>ID Number</th>
<th>Email</th>
<th>Client Type</th>
<th>Created </th>
</thead>
@foreach($clients as $client)
<tr>
<td>{{$client->customercode}}</td>
<td>{{$client->name}}</td>
<td>{{$client->surname}}</td>
<td>{{$client->companyname}}</td>
<td>{{$client->idnumber}}</td>
<td>{{$client->email}}</td>
<td>{{$client->clienttype}}</td>
<td>{{$client->created_at}}</td>
</tr>
@endforeach
</table>
{{$clients->appends(Request::except('page'))->links()}}
</div>
</div>
</div>
</div>
</div>
<div class="content">
<div class="row search">
<div class="col-xs-12">
<div class="box" >
<div class="box-body" >
<table class="table table-bordered table-hover" id="bankings">
<thead>
<th>Customer Code</th>
<th>Account Holder's Name</th>
<th>Bank</th>
<th>Account Type</th>
<th>Account Number</th>
</thead>
@foreach($bankings as $banking)
<tr>
<td>{{$banking->customercode}}</td>
<td>{{$banking->acc_holders_name}}</td>
<td>{{$banking->bank}}</td>
<td>{{$banking->acc_type}}</td>
<td>{{$banking->acc_no}}</td>
</tr>
@endforeach
</table>
{{$bankings->appends(Request::except('page2'))->links()}}
</div>
</div>
</div>
</div>
</div>
@stop
所以我有一个搜索功能,通过2个表,即客户端&amp;银行根据用户输入进行搜索,并返回与输入匹配的结果。所以我在两个表上添加了简单的laravel分页。我的问题是,当我点击客户端表结果上的第2页时,它还会对Bankings表结果进行分页。我怎么能让它一次只分页一个表而不是两个?请帮忙
答案 0 :(得分:0)
您可以添加&#39;名称&#39;你分页的事情:
在网址中,它现在是?clients=1&bankings=3
等。
public function getSearch(Request $request)
{
$search = $request->input('search');
$clients = Client::search($search)
->paginate(5, ['*'], 'clients');
$bankings = Banking::search($search)
->paginate(5, ['*'], 'bankings');
return view('search/search',compact(['clients','bankings']));
}
https://laravel.com/api/5.5/Illuminate/Database/Eloquent/Builder.html#method_paginate