Im struggling to match the date value in the MySQL server with the jquery UI input date
This is what i have tried
$('#start_date').datepicker({dateFormat:'dd-mm-yy'});
ajax call
$(document).on('change', '#hotelid', function() {
var hotid = $('#hotelid').val();
onHotelIdUpdate(hotid);
});
function onHotelIdUpdate(val) {
var bookdate = $('#start_date').val();
console.log('onHotelIdUpdate() called with the val: ', val);
$.ajax({
type:'get',
url: "{{ route('hotel.rate') }}",
data:{
'_token':$('input[name=_token]').val(),
'hotelid': val,
'bookdate': bookdate
},
success:function(data){
console.log(data);
$("#avail").val(data.rooms);
},
error: function(){
console.log("Error Occurred");
}
my controller function in laravel
public function getRates(Request $request )
{
$hotelid = $request->input('hotelid');
$date = $request->input('bookdate');
$rates=hotelroom::where('hotel_id',$hotelid)
->where('available_date',$date)
->first();
return response()->json($rates);
}
This works fine without the "bookdate" variable im sending but when i include it returns blank record
i have also notices in the input checkbox the date is showing as " dd-mm-yyyy' but in the database the date value im trying to match has the date as " yyyy-mm-dd" how to fix this ?