Currently, I am using Laravel in my project and I need to modify the patient's status when they schedule an appointment with a doctor. The patient can have one of three statuses: Accept, Waiting (automatically assigned when the patient selects a date and time), or Not Accept. However, I am encountering an issue where clicking on the active button does not result in any changes in the database.
This is the controller responsible for changing the status:
public function changeStatus(Request $request)
{
$user = rdv::find($request->IDP);
$user->Etat_de_rdv = $request->status;
$user->save();
return response()->json(['success'=>'Status changed successfully.']);
}
This is the controller used when a patient schedules an appointment:
public function rdv(Request $request) {
// Variables: input values
$date=$request->input('time');
$time=$request->input('date');
$doctor=$request->input('goID');
// Array to compare inputs to existing values in the database
$att = [
'IDD' => $doctor,
'time' => $time,
'date' => $date
];
$data=rendezvous::where($att)->first();
// Required inputs
$this->validate($request, [
'np' => 'required',
'tel' => 'required',
'date' => 'required',
'time' => 'required',
]);
// Adding to rendezvous
$rdv = new rendezvous() ;
$patient_id=$request->session()->get('patient_id');
$rdv->Nom_et_prénom=$request->input('np');
$rdv->Numéro_de_téléphone=$request->input('tel');
$rdv->IDD=$request->input('goID');
$rdv->date=$request->input('time');
$rdv->time=$request->input('date');
$rdv->IDP=$patient_id;
// Checking if data already exists
if ($data!==null) {
return redirect()->back()->withErrors('Time and date are occupied, please choose another!' ) ;
}
$rdv-> save();
return redirect("/rendezvous_$doctor")->withSuccess('Appointment saved, please check the status of your appointment!') ;
}
This is the view that the doctor sees with all appointments:
<h3> Your patients :</h3>
@foreach($pat as $lo)
@if ($lo->IDD== $med->ID)
<div class="admin">
<div class="info">
<h3> {{ $lo->Nom_et_prénom }} </h3>
<p>{{ $lo->Numéro_de_téléphone }}</p>
<p>{{ $lo->date}}</p>
<p>{{ $lo->time }}</p>
<input data-id="{{$lo->IPD}}" class="toggle-class" type="checkbox" data-onstyle="success" data-offstyle="danger" data-toggle="toggle" data-on="Accept" data-off="Busy Time" {{ $lo->Etat_de_rdv ? 'checked' : '' }}>
</div>
</div>
@endif
@endforeach
This is the Ajax script:
<script>
$(function() {
$('.toggle-class').change(function() {
var Etat_de_rdv = $(this).prop('checked') == true ? Accept : Busy Time;
var id = $(this).data('IPD');
$.ajax({
type: "GET",
dataType: "json",
url: '/changeStatus',
data: {'Etat_de_rdv': 'status', 'IDP': id},
success: function(data){
console.log(data.success)
}
});
})
})
</script>