I am using FullCalendar, and when i select a square (date) i show a modal i insert info ( title , objectif .. etc) once I click on 'save changes' the event is added not to the selected date but to my current date!
( **I ll try to explain it more , I select for example the date 15-04-2022 and i insert my information and click 'save changes ' but the event is being added to my local date which is the 19-04-2022 ** )
MyReservations.blade.php
Add New Reservation
<div class="modal-body">
<!-- Room -->
<select class="form-control" aria-label="Default select example" id="room_id" required >
<option selected>Select Room</option>
@foreach($room as $items)
<option value="{{$items->id}}">{{$items->id}}</option>
@endforeach
</select>
<br>
<!-- Title -->
<div class="input-group">
<span class="input-group-text"> Title : </span>
<input class="form-control" aria-label="Title" id="title" required> </input>
</div>
<br>
<!-- Objectif -->
<div class="input-group">
<span class="input-group-text">Objectif :</span>
<textarea class="form-control" aria-label="Objectif" id="objectif" required></textarea>
</div>
<br>
<!-- Time -->
<div class="input-group">
<span class="input-group-text">TimeLine :</span>
<select class="form-control" id="cre" required >
<option></option>
<option value="8:30-10:30">8.30-10.30</option>
<option value="10:30-12:30">10.30-12.30</option>
<option value="13:30-15:30">13.30-15.30</option>
</select>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
<button type="button" id="submit" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
<div id="calendar">
</div>
</div>
</div>
</div>
<script>
$(document).ready(function() {
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
var events = @json($events);
$('#calendar').fullCalendar({
header:{
left:'prev,next today',
center:'title',
right:'month, agendaWeek, agendaDay'
},
events: events,
selectable:true,
selectHelper:true,
select: function(start, end, allDays) {
$('#ResModal').modal('toggle');
$('#submit').click(function () {
var title = $("#title").val();
var objectif = $("#objectif").val();
var room_id = $("#room_id").val();
var cre = $("#cre").val();
var start = moment (start).format('YYYY-MM-DD');
var end = moment (end).format('YYYY-MM-DD');
$.ajax({
url: "{{route('MyReservations.store')}}",
type: "POST",
dataType: 'json',
data: {title: title, start: start, end: end, room_id: room_id, objectif: objectif ,cre: cre},
success: function (response)
{
$('#ResModal').modal('hide');
$('#calendar').fullCalendar('renderEvent', {
'title' : response.title,
'start' : response.start ,
'end' : response.end,
});
},
});
});
},
})
});
</script>
NOTE: it was working perfectly before I added: the cre as a column in my DB and in my blade, my controller ..etc
-- in my migration cre is type String --