FullCalendar get events from database Code Answer

Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of FullCalendar get events from database without wasting too much if your time.

The question is published on by Tutorial Guruji team.

Hi i am using FullCalendar in a laravel project and i need to display the events from the database.

I get all the events from the database and display them using json_encode.

There is the code i use :

My controller :

<?php

namespace AppHttpControllers;
use AppHttpGestionnairesEventGestionnaire;
use IlluminateHttpRequest;

class EventController extends Controller
{
    public function afficher(){

        $eventGestionnaire = new EventGestionnaire;
        $listeEvents = $eventGestionnaire->getListeEvents();

        echo json_encode($listeEvents);


        return view('pages.calendar');

    }
}

And my script :

$calendar.fullCalendar({

    viewRender: function(view, element) {
        if (view.name != 'month'){

            $(element).find('.fc-scroller').perfectScrollbar();

        }
    },

    resourceEditable: true,
    eventLimit: true,
    editable: true,
    selectable: true,
    selectHelper: true,
    header: {
        left: 'month,agendaWeek,agendaDay',
        center: 'title',
        right: 'prev,next,today'
    },

    events: 'EventController.php',

The error :

jquery.min.js:3049 GET http://localhost/planner/public/EventController.php?start=2019-09-01&end=2019-10-13&_=1568831263931 404 (Not Found)

Answer

From FullCallendar V3 DOCS to pass URL with JSON response use

$('#calendar').fullCalendar({

  eventSources: [

    // your event source
    {
      url: '/myfeed.php', // use the `url` property
      color: 'yellow',    // an option!
      textColor: 'black'  // an option!
    }

    // any other sources...

  ]

});
We are here to answer your question about FullCalendar get events from database - If you find the proper solution, please don't forgot to share this with your team members.

Related Posts

Tutorial Guruji