Reputation: 207
i'am working in laravel project , so i want to change the status of patient when he take an appointement with doctor , so he can have 3 satuts , Accept , waiting , not accept , i'am asking how can i change the satatus with only clicking on button and thank you .
This is controller witch the doctor edit an appointement :
public function edit ($id) {
$rdv= rendezvous::find($id);
return view ('/edit', ['modifier'=>$rdv]); }
this is the view witch the doctor can see his patients and edit or accept or reject an appointement
<h3> the patients :</h3>
@foreach($patient as $pat)
@if ($pat->IDD== $doctor->ID)
<div class="admin">
<div class="info">
<h3> {{ $pat->Name_Last_Name }} </h3>
<p>{{ $pat->phone_number }}</p>
</div>
</div>
<a class="btn btn-info" href="{{url('edit/'.$pat->id) }}" > edit </a>
@endif
@endforeach
Upvotes: 0
Views: 922
Reputation: 835
Thanks for your clarification.
Let's consider, once you got appointment, then status will be not-accepted
automatically. Once you click on chanage status
btn then it will change to waiting
and at last accepted
.
In your blade -
<a onclick="status({{$pat->id}})" class="btn">Change Status</a>
In js -
function status(id) {
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
$.ajax({
type: "POST",
url: '/update-status',
data: {
'id': id
},
success: function(data){
//redirect where you want..
},
});
};
In your controller -
public function status(Request $request){
$id = $request->id;
$status = rendezvous::where('id', $id)->value('status');
if($status === 'not-accepted'){
$status = 'waiting';
} elseif($status === 'waiting'){
$status = 'accepted';
}
rendezvous::where('id', $id)->update(['status'=> $status]);
return response()->json('success');
}
Hope this will work.
Upvotes: 1