0
votes

Controller

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'])); 

}

View

@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

So i have a search functionality that goes through 2 tables namely Clients & Bankings to search based on user input and bring back the results matching the input. So i added simple laravel pagination on both tables. My Issue is when i click page 2 on Clients table results it also paginates Bankings table results. How can i make it to only paginate one table at a time not both ? Please help

1

1 Answers

0
votes

You can add 'names' to the things your paginating:

In the url it will now be ?clients=1&bankings=3 etc.

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