I’m using Laravel Framework 6.20.44, PHP 7.2.25, and MySQL. The problem I’m facing is that when I perform a search using a batch number, the expected results are not displayed. Instead, it shows the same data that was initially displayed. Additionally, when I enter a search term that is not found in the database, the “No Data Found” message is not being shown.
//Here’s the route
Route::get(‘application_batches/index’, ‘ApplicationBatchController@searchBatchNum’);
//Here’s the index blade
@extends('layouts.app')
   @section('content')
    @if(session()->get('status'))
        <strong>{{ session('status') }}</strong>
        ×
    @endif
    <div class="card">
        <div class='card-header text-center bg-primary text-white'>
            <h1>Visa Application Batches</h1>
        </div>
        <div class="col-md-8 offset-md-2">
            <input type="text" id="batchNum" name="batchNum" class="form-control text-center" 
                placeholder="Type batch number to search">
        </div>
        <button class="btn btn-primary">Search</button>
        <div id='application_list'>
            @include('application_batches.applicationBatch_list')
        </div>
        <table>
            <!-- table content -->
        </table>
        <div class="row">
            <div class="col-md-12 text-center">
                <a href="{{url('/')}}" class="btn btn-danger">Back</a>
            </div>
        </div>
    </div>
@endsection
@section('scripts')
function searchBatchNum(page) {
    $.ajax({
        url: "application_batches/index?page=" + page,
        data: { searchString: $('#batchNum').val() },
        success: function(data) {
            $('#index').html(data);
        }
    });
}
$(document).on('click', '.pagination a', function(event) {
    event.preventDefault();
    var page = $(this).attr('href').split('page=')[1];
    searchBatchNum(page);
});
$(document).on('keyup', '#batchNum', function() {
    searchBatchNum(1);
});
});
@endsection
//Here’s another blade named “applicationBatch_list”
<div class="table-responsive">
    <table class="table table-striped table-hover text-center" id="applicantIndex">
        <thead class="thead-dark">
            <tr>
                <th style="width:30%">Batch No</th>
                <th style="width:30%">Batch Date</th>
                <th style="width:30%">Status</th>
                <th style="width:10%"></th>
            </tr>
        </thead>
        <tbody>
            @if($application_batches->count() >0)
                @foreach($application_batches as $batch)
                    <tr>
                        <td>{{ $batch->batch_no }}</td>
                        <td>{{ $batch->batch_date }}</td>
                        <td>{{ $batch->receive_status }}</td>
                        <td><a href="{{ route('application_batches.edit', $batch->id) }}" class="btn btn-primary">View</a></td>
                    </tr>
                @endforeach
            @else
                <tr>
                    <td colspan="4" class="text-center font-weight-bold">No Data Found</td>
                </tr>
            @endif
        </tbody>
    </table>
    {!! $application_batches->links() !!}
</div>
//And finally the ApplicationBatchController
   class ApplicationBatchController extends Controller
{
/**
* Display a listing of the resource.
*
* @return IlluminateHttpResponse
*/
public function index()
{
if (Auth::user()->branch == 'MNL') {
$application_batches = DB::table('application_batches')
->leftJoin('applications', 'application_batches.batch_no', '=', 'applications.batch_no')
->where('applications.branch', 'MNL')
->orWhere('application_batches.status', '2')
->orWhere('application_batches.status', '3')
->orWhere('application_batches.status', '6')
->orWhere('application_batches.status', '7')
->orWhere('application_batches.status', '8')
->select('application_batches.id', 'application_batches.batch_no', 'application_batches.batch_date', 'application_batches.status', 'application_batches.total_applications')
->groupBy('application_batches.id', 'application_batches.batch_no', 'application_batches.batch_date', 'application_batches.status', 'application_batches.total_applications')
->orderBy('application_batches.batch_date', 'desc')->paginate(20);
} else {
$application_batches = DB::table('application_batches')
->leftJoin('applications', 'application_batches.batch_no', '=', 'applications.batch_no')
->where('applications.branch', Auth::user()->branch)
->select('application_batches.id', 'application_batches.batch_no', 'application_batches.batch_date', 'application_batches.status', 'application_batches.total_applications')
->groupBy('application_batches.id', 'application_batches.batch_no', 'application_batches.batch_date', 'application_batches.status', 'application_batches.total_applications')
->orderBy('application_batches.batch_date', 'desc')->paginate(20);
}
    $status_array = ApplicationBatchStatus::all();
    $status_list = array();
    foreach ($status_array as $status) {
        $status_list[$status->id] = $status->description;
    }
    foreach ($application_batches as $batch) {
        if ($batch->status == 2) {
            $batch->receive_status = $status_list[$batch->status] . " (" . $batch->total_applications . "/" . $batch->total_applications . ")";
        } else {
            $batch->receive_status = $status_list[$batch->status];
        }
    }
    return view('application_batches.index', compact('application_batches'));
}
public function searchBatchNum(Request $request)
{
    if ($request->ajax()) {
        $searchString = $request->get('searchString');
        if ($searchString != '') {
            $data = DB::table('application_batches')
                ->where(function($query) use ($searchString) {
                    $query->where('batch_no', 'LIKE', '%' . $searchString . '%')
                        ->orWhere('status', 'LIKE', '%' . $searchString . '%');
                })
                ->orderBy('id', 'desc')
                ->paginate(20);
        } else {
            $data = DB::table('application_batches')->orderBy('id', 'desc')->paginate(20);
        }
        return view('application_batches.applicationBatch_list', compact('data'))->render()->content();
    }
}
}
I want to display the searched data based on the batch number.