look in network tools in your browser
Is the post to the correct endpoint?
Is the search term being passed along?
What is the response?
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I can't find the error with this one. No error appears in my laravel.log so I tried tracing it but to no avail. I'm for any suggestions.
js
$('body').on('keyup','#search-patients',function()
{
var keyword = $(this).val();
$.ajax({
type: "POST",
url: "{{ route('searchPatients')}}",
dataType: "json",
data: {keyword: keyword,
_token: '{{csrf_token()}}'
},
success: function(res){
$('#dynamic-row').empty();
$('#dynamic-row').append(res);
}
});
});
controller
public function searchPatients(Request $request)
{
$keyword = $request->get('keyword');
$patient_admissions = DB::table('patients')
->join('admissions', 'patients.id', '=', 'admissions.patient_id')
->select('patients.id','patients.last_name as lname', 'patients.first_name as fname', 'patients.middle_name as mname', 'patients.suffix_name as sname', 'patients.status as status', 'admissions.admission_date_time as admission', 'admissions.discharge_date_time as discharge')
->where(function ($query) use ($keyword) {
$query->where('patients.id', 'LIKE', '%'.$keyword.'%')
->orWhere('patients.first_name', 'LIKE', '%'.$keyword.'%')
->orWhere('patients.middle_name', 'LIKE', '%'.$keyword.'%')
->orWhere('patients.last_name', 'LIKE', '%'.$keyword.'%')
->orWhere('patients.suffix_name', 'LIKE', '%'.$keyword.'%')
->orWhere('patients.address', 'LIKE', '%'.$keyword.'%')
->orWhere('patients.birthdate', 'LIKE', '%'.$keyword.'%')
->orWhere('patients.status', 'LIKE', '%'.$keyword.'%');
})
->get();
return view('includes.partials.patientSearch', compact('patient_admissions'))->render();
}
partial blade
@foreach ($patient_admissions as $patient_admission)
<tr>
<td><b><?php if(empty($patient_admission->mname) && isset($patient_admission->sname) ) {
echo strtoupper($patient_admission->lname.', '.$patient_admission->fname.', '.$patient_admission->sname);
} else if (empty($patient_admission->sname) && isset($patient_admission->mname)){
echo strtoupper($patient_admission->lname.', '.$patient_admission->fname.', '.$patient_admission->mname);
} else if (empty($patient_admission->sname) && empty($patient_admission->mname)){
echo strtoupper($patient_admission->lname.', '.$patient_admission->fname);
}else {
echo strtoupper($patient_admission->lname.', '.$patient_admission->fname.', '.$patient_admission->mname.', '.$patient_admission->sname);
} ?></b></td>
<td><b>{{ strtoupper($patient_admission->status); }}</b></td>
<td><b><?php $date = date_create($patient_admission->admission); echo date_format($date, "h:i A - M. d") ?></b></td>
<td><b><?php if(is_null($patient_admission->discharge)){ echo 'N/A';}else{$date = date_create($patient_admission->discharge); echo date_format($date, "h:i A");} ?></b></td>
<td><a class="btn btn-outline-warning btn-sm" id="buttonEdit" href="{{ route('patients.show', $patient_admission->id)}}"><b>VIEW</b></a> <a class="btn btn-outline-info btn-sm" id="buttonEdit" href="{{ route('patients.edit', $patient_admission->id)}}"><b>EDIT</b></a> <a class="btn btn-outline-danger btn-sm" id="buttonEdit" href="{{ route('patientSoftDelete', $patient_admission->id) }}"><b>DELETE</b></a></td>
</tr>
@
@Snapey so this is what I did and it works just fine but I don't know if it's the best way to do it
$results = view('includes.partials.patientSearch', compact('patient_admissions'));
$view = $results->render();
return json_encode($view);
I think after rendering the results to the partial blade, the partial blade has no way of finding it's way back to the ajax to append the results
Please or to participate in this conversation.