Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

kylie's avatar
Level 1

my start and end date always gives me my local time instead of selected date in the fullCalendar - Laravel

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 --

0 likes
6 replies
Snapey's avatar

easy enough to console log start and end in your javascript

or look at the browser ajax request and see what is sent

if it turns out you are sending the right value then you are going to have to reveal your controller method

there are far easier ways of detecting the error than having us look at the code

kylie's avatar
Level 1

@Snapey i tried these ways , and being a beginner is something like this sir :) you ask for help and people guide you , you as a senior can find issues easier than others , also can thik about multiple solutions we can not .. there is no harm in showing the code and getting some help sir :)

Snapey's avatar

@Hadjer25 but you have not shown the code? We don't know what your controller does

And, frankly, if you want to be a web developer then you need to understand how to use the developer tools in the browser

kylie's avatar
Level 1

@Snapey Yes I want to , and I am learning to be Sir

anyways thank you so much Sir for your HELP I appreciate it.

Please or to participate in this conversation.