Search code examples
javascriptlaravelfullcalendarfullcalendar-5

Display database query results as event text (Laravel 7, FullCalendar 5)


I am getting some columns from my database as an event feed from my controller:

$events = DB::table('toolplanview')
  ->select('id', 'eventId', 'resourceId', 'title', 'start', 'end')
  ->get();
return json_encode($events);

Per default, Calendar displays the title on the events but I need to also show the eventId. I can get some info using

eventContent: function(info) {
  return info.event.title + " (Start: " + info.event.start +")";
},

in my Calendar definition in my view but I can't figure out how to access all the other columns from the event feed / query results. I browsed the docs and could not find any array where they might be.


Solution

  • If you have non-standard fields in your event objects, then as per the Event Parsing documentation, fullCalendar will place these inside the extendedProps object which becomes part of the event object within fullCalendar.

    So to get a field called eventId from your original data, you should be able to use info.event.extendedProps.eventId to access it. e.g.

    eventContent: function(info) {
      return info.event.extendedProps.eventId + ": " + info.event.title + " (Start: " + info.event.start +")";
    },