In my calendar I want to show appoinmtents for the specific date. When a user clicks on date a form would slide down and it would have details but I tried with ajax and jquery to do this. I get the data and with ajax and I tried to console log it and I did get data there but its showing same data on all dates and I haven't found any solution for this.
<div id="calendar" style="width: 100%"
@foreach($ress as $res)data-id="{{ $res->id }}" data-content="{{ $res->name }}" @endforeach
onclick="getDetails(this)">
</div>
this is where my calendar shows up
function getDetails(myObj) {
$(document).ready(function () {
$('.day').click(function () {
var id = $(myObj).data('id');
$.ajax({
url: '{{ route('get.details') }}',
type: "GET",
data: {
res_id: id,
'_token': $('input[name=_token]').val()
},
success: function (res) {
var response = $(res);
console.log(response);
},
error: function (err) {
console.log(err);
}
});
});
});
}
this is my ajax function to get appointments
public function getDetails(Request $request)
{
$response = Reservation::findOrFail($request->res_id);
return response()->json(['success'=>'yes it works','response'=>$response]);
}
This is my method in controller
What I want to happen is when I click on a date it should only bring it's appointments set by the admin and I have failed miserably in trying to do that I will be really thankful if anyone can guide me here.