Define routes at routes/web.php
//All certificates Route::post('/search-certificates', '[email protected]' ); Route::get('/search-certificates', '[email protected]' ); or Route::any('/search-certificates', '[email protected]' );
Define Controller function Search
public function search(Request $request){ $searchString = $request->input('searchString'); $searchCertificates = DB::table('NAMEOFYOURBABLE') ->where('BOROUGH', 'like', "%$searchString%" ) ->orwhere('STREET', 'like', "%$searchString%" ) ->orwhere('POSTCODE', 'like', "%$searchString%" ) ->orderBy('POSTCODE', 'asc') ->orderBy('NUMBER', 'asc') ->orderBy('JOB_NUMBER', 'asc') ->paginate(20); $searchCertificates->appends(['searchString' => $searchString]); return view('search-certificates', ['searchCertificates' => $searchCertificates]); }
Most important line on the code above is the one below because it will allow search pagination
$searchCertificates->appends(['searchString' => $searchString]);
Define View Laravel Blade Page
Form
<form action="/search-certificates" method="POST" role="search"> {{ csrf_field() }} <div class="input-group"> <input type="text" class="form-control" name="searchString" placeholder="Search by Street or Postal Code " /> <button type="submit" class="btn btn-primary">Submit</button> </div> </form>
Grid/Table
<div class="row justify-content-center">
<table class="table table-striped">
<thead>
<tr>
<th>POSTCODE</th>
<th>ISSUE_TYPE</th>
<th>C_O_ISSUE_DATE</th>
<th>BOROUGH</th>
<th>NUMBER</th>
<th>STREET</th>
<th>Number of Units</th>
<th>NTA</th>
</tr>
</thead>
<tbody>
@foreach ($searchCertificates as $oneCertificate)
<tr>
<td>{{ $oneCertificate->POSTCODE }}</td>
<td>{{ $oneCertificate->ISSUE_TYPE }}</td>
<td>{{ $oneCertificate->C_O_ISSUE_DATE }}</td>
<td> {{ $oneCertificate->BOROUGH }}</td>
<td>{{ $oneCertificate->NUMBER }}</td>
<td>{{ $oneCertificate->STREET }}</td>
<td>{{ $oneCertificate->PR_DWELLING_UNIT }}</td>
<td>{{ $oneCertificate->NTA }}</td>
</tr>
@endforeach
</tbody>
Blade Pagination Link
{{ $searchCertificates->links( "pagination::bootstrap-4") }}