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

thorbym's avatar

Fullcalendar not displaying events correctly

I am quickly building (or attempting to) a site using laravel and fullcalendar. I've implemented it in the "old school" way, with CDN links in app.blade.php and jquery at the bottom of that file too. jQuery below

For some reason it's correctly fetching the 3 test events from the DB, but displaying them incorrectly. Has anyone had this happen before?

<!doctype html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <!-- CSRF Token -->
    <meta name="csrf-token" content="{{ csrf_token() }}">

    <title>{{ config('app.name', 'Laravel') }}</title>

    <!-- Scripts -->
    <script src="{{ asset('js/app.js') }}"></script>

    <!-- Fonts -->
    <link rel="dns-prefetch" href="//fonts.gstatic.com">
    <link href="https://fonts.googleapis.com/css?family=Nunito" rel="stylesheet">

    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/3.10.1/fullcalendar.min.css" integrity="sha256-tXJP+v7nTXzBaEuLtVup1zxWFRV2jyVemY+Ir6/CTQU=" crossorigin="anonymous" />
    <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.25.3/moment.min.js" integrity="sha256-C66CaAImteEKZPYvgng9j10J/45e9sAuZyfPYCwp4gE=" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/3.10.1/fullcalendar.min.js" integrity="sha256-O04jvi1wzlLxXK6xi8spqNTjX8XuHsEOfaBRbbfUbJI=" crossorigin="anonymous"></script>
    <!-- Styles -->
    <link href="{{ asset('css/app.css') }}" rel="stylesheet">
</head>
<body>
    <div id="app">
        <nav class="navbar navbar-expand-md navbar-light bg-white shadow-sm">
            <div class="container">
                <a class="navbar-brand" href="{{ url('/') }}">
                    {{ config('app.name', 'Laravel') }}
                </a>
                <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="{{ __('Toggle navigation') }}">
                    <span class="navbar-toggler-icon"></span>
                </button>

                <div class="collapse navbar-collapse" id="navbarSupportedContent">
                    <!-- Left Side Of Navbar -->
                    <ul class="navbar-nav mr-auto">

                    </ul>

                    <!-- Right Side Of Navbar -->
                    <ul class="navbar-nav ml-auto">
                        <!-- Authentication Links -->
                        @guest
                            <li class="nav-item">
                                <a class="nav-link" href="{{ route('login') }}">{{ __('Login') }}</a>
                            </li>
                            @if (Route::has('register'))
                                <li class="nav-item">
                                    <a class="nav-link" href="{{ route('register') }}">{{ __('Register') }}</a>
                                </li>
                            @endif
                        @else
                            <li class="nav-item dropdown">
                                <a id="navbarDropdown" class="nav-link dropdown-toggle" href="#" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" v-pre>
                                    {{ Auth::user()->name }} <span class="caret"></span>
                                </a>

                                <div class="dropdown-menu dropdown-menu-right" aria-labelledby="navbarDropdown">
                                    <a class="dropdown-item" href="{{ route('logout') }}"
                                       onclick="event.preventDefault();
                                                     document.getElementById('logout-form').submit();">
                                        {{ __('Logout') }}
                                    </a>

                                    <form id="logout-form" action="{{ route('logout') }}" method="POST" style="display: none;">
                                        @csrf
                                    </form>
                                </div>
                            </li>
                        @endguest
                    </ul>
                </div>
            </div>
        </nav>

        <main class="py-4">
            @yield('content')
        </main>
    </div>
</body>
<script>

    var events = @json($events);

    $(document).ready(function () {

        var SITEURL = "{{url('/')}}";

        $.ajaxSetup({
            headers: {
                'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
            }
        });

        var calendar = $('#calendar').fullCalendar({
            events: events,
            defaultView: 'agendaDay',
            minTime: "07:00:00",
            maxTime: "18:00:00",
        });
    });

</script>
</html>
0 likes
11 replies
thorbym's avatar

I tried to post a screengrab, but don't seem to be able to ...

Tray2's avatar

It might have to do with the time format. The times from the database is in 24H format while it seems that the one being presented is in 12H format.

thorbym's avatar

Hmm. Thank you for the suggestion, but I don't think that's the issue - as it's displaying the time of "event 3" as 1.30pm (which is correct), but then rendering it at the time of the 2nd event!

thorbym's avatar
thorbym
OP
Best Answer
Level 1

I abandoned the project using v3 fullcalendar, and attempted an install of v4 using NPM.

It was tough at first, figuring out how to add the files on bootstrap.js and set them as globally available, but I've got there in the end!

Thanks for viewing / helping

bngaard's avatar

How did you do this? I am struggling with the same issue when upgrading to v4

thorbym's avatar

Hey. So. It was nowhere near as scary as I thought it would be!

Follow this guide: https://fullcalendar.io/docs/getting-started

Install fullcalendar using NPM, bearing in mind that you will need further plugins if you wish to use other fullcalendar functionality.

I installed core, timegrid, interaction and boostrap. So you need to do npm install --save @fullcalendar/core @fullcalendar/{whateverPluginYouNeed} @fullcalendar/{maybeAnotherOne}

Once that's installed, you need to include the files in the "try" block of your "bootstrap.js" file in Laravel. So I have:

require('@fullcalendar/core');
require('@fullcalendar/timegrid');
require('@fullcalendar/interaction');
require('@fullcalendar/bootstrap');

Then, at the bottom of the same file, you need to import the js modules and attach them to the "window" to use across your site. So I have:

import { Calendar } from '@fullcalendar/core';
import timeGridPlugin from '@fullcalendar/timegrid';
import interaction from '@fullcalendar/interaction';
import bootstrapPlugin from '@fullcalendar/bootstrap';

window.Calendar = { Calendar };
window.timeGridPlugin = timeGridPlugin;
window.interaction = interaction;
window.bootstrapPlugin = bootstrapPlugin;

Then, in the file in which I want my calendar, I have a div with an id of "calendar" and some javascript:

document.addEventListener('DOMContentLoaded', function() {

        var calendarEl = document.getElementById('calendar');

        var calendar = new Calendar.Calendar(calendarEl, {
            	defaultView: 'timeGridDay',
		stuff: 'thing'
	});
});
		
ajsmith_codes's avatar

@thorbym

I am trying this but not having any luck. I don't see a "try" statement in my bootstrap.js file. Is that a try/catch? If so, what is the code you have for that?

I'm also getting a 404 in regards to the @fullcalendar statement. Any ideas?

thorbym's avatar

Hi there @ajsmith_codes , apologies for the delay in my reply, I didn't get a notification email for this comment :(

Firstly, have you installed it so you can see the @fullcalendar folder within your node_modules folder? If not, be sure to follow this from the fullcalendar website:

"FullCalendar is available on NPM or Yarn. You’ll first need to install FullCalendar’s core package as well as any plugins. Example:

npm install --save @fullcalendar/core @fullcalendar/daygrid"

If it is installed, my bootstrap.js file is as follows:

window._ = require('lodash');

/**
 * We'll load jQuery and the Bootstrap jQuery plugin which provides support
 * for JavaScript based Bootstrap features such as modals and tabs. This
 * code may be modified to fit the specific needs of your application.
 */

try {
    window.Popper = require('popper.js').default;
    window.$ = window.jQuery = require('jquery');

    require('bootstrap');
    require('bootstrap-colorpicker');
    require('datatables.net');
    require('datatables.net-bs4');
    require('jquery-timepicker/jquery.timepicker.js');
    require('@fullcalendar/core');
    require('@fullcalendar/timegrid');
    require('@fullcalendar/interaction');
    require('@fullcalendar/core/locales/en-gb');
    require('@fullcalendar/bootstrap');
} catch (e) {}

/**
 * We'll load the axios HTTP library which allows us to easily issue requests
 * to our Laravel back-end. This library automatically handles sending the
 * CSRF token as a header based on the value of the "XSRF" token cookie.
 */

window.axios = require('axios');

window.axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';

/**
 * Echo exposes an expressive API for subscribing to channels and listening
 * for events that are broadcast by Laravel. Echo and event broadcasting
 * allows your team to easily build robust real-time web applications.
 */

// import Echo from 'laravel-echo';

// window.Pusher = require('pusher-js');

// window.Echo = new Echo({
//     broadcaster: 'pusher',
//     key: process.env.MIX_PUSHER_APP_KEY,
//     cluster: process.env.MIX_PUSHER_APP_CLUSTER,
//     encrypted: true
// });

/** Full calendar section
**/
import { Calendar } from '@fullcalendar/core';
import timeGridPlugin from '@fullcalendar/timegrid';
import interaction from '@fullcalendar/interaction';
import bootstrapPlugin from '@fullcalendar/bootstrap';

window.Calendar = { Calendar };
window.timeGridPlugin = timeGridPlugin;
window.interaction = interaction;
window.bootstrapPlugin = bootstrapPlugin;

ajsmith_codes's avatar

@thorbym I also didn't receive an emai notification for this. Weird!

I have followed what you have, but still not working. What version of Laravel are you using? I am using v7.

ajsmith_codes's avatar

I gave up on Fullcalendar and went with Dhtmlx Scheduler. Much easier to work with.

Please or to participate in this conversation.