title: how to fetch FullCalendar events from laravel controller..?
body: <p>I'm working on a fullcalendar page for my website. Their documentation doesnt explain much about fetching events from a controller url.
  Right now I'm being able to add new events into the database.., but those events aren't showing on the calendar..and for the same reason I cant update or delete the events from it.</p>
  
  <p>This is the javascript code in my calendar.php view page.</p>
  
  <pre><code>&lt;script src='http://fullcalendar.io/js/fullcalendar-2.3.1/lib/moment.min.js'&gt;&lt;/script&gt;
  &lt;script src='http://fullcalendar.io/js/fullcalendar-2.3.1/lib/jquery.min.js'&gt;&lt;/script&gt;
  &lt;script src='http://fullcalendar.io/js/fullcalendar-2.3.1/lib/jquery-ui.custom.min.js'&gt;&lt;/script&gt;
  &lt;script src='http://fullcalendar.io/js/fullcalendar-2.3.1/fullcalendar.js'&gt;&lt;/script&gt;
  
  $(document).ready(function() {
  
      var currentMousePos = {
          x: -1,
          y: -1
      };
  
      jQuery(document).on("mousemove", function (event) {
          currentMousePos.x = event.pageX;
          currentMousePos.y = event.pageY;
      });
  
      /* initialize the external events
       -----------------------------------------------------------------*/
  
  
      $('#external-events div.external-event').each(function() {
  
          // store data so the calendar knows to render an event upon drop
          $(this).data('event', {
              title: $.trim($(this).text()), // use the element's text as the event title
              stick: true // maintain when user navigates (see docs on the renderEvent method)
          });
  
          // make the event draggable using jQuery UI
          $(this).draggable({
              zIndex: 1111999,
              revert: true,      // will cause the event to go back to its
              revertDuration: 0  //  original position after the drag
          });
  
      });
  
  
      /* initialize the calendar
       -----------------------------------------------------------------*/
      var date = new Date();
      var d = date.getDate();
      var m = date.getMonth();
      var y = date.getFullYear();
  
      var calendar=$('#calendar');
  
      calendar.fullCalendar({
          header: {
              left: 'prev,next today',
              center: 'title',
              right: 'month,agendaWeek,agendaDay'
          },
          editable: true,
          droppable: true, // this allows things to be dropped onto the calendar
          drop: function() {
              // is the "remove after drop" checkbox checked?
              if ($('#drop-remove').is(':checked')) {
                  // if so, remove the element from the "Draggable Events" list
                  $(this).remove();
              }
          },
  
          eventSources: [
  
              {
  
                  url: '/v1/calendar/',
                  type: 'GET',
                  dataType:'json',
  
  
              },
  
          ],
  
          selectable: true,
          selectHelper: true,
          select: function(start, end, allDay) {
  
              bootbox.prompt("New Event Title:", function(title) {
                  var people_id=1;
                  //var title=event.title;
                  //var start=event.start;
                  //var end=event.end;
  
                  if (title !== null) {
                      calendar.fullCalendar('renderEvent',
                              {
                                  people_id:people_id,
                                  title: title,
                                  start: start,
                                  end: end,
                                  allDay: allDay
                              },
  
                      true // make the event "stick"
  
  
                              );
  
                              var myDate = new Date( start *1000);
                              var startdate=myDate.toLocaleString();
                              var Datetwo = new Date( end *1000);
                              var enddate=Datetwo.toLocaleString();
  
  
  
  
                              $.ajax({
                                   url: '/v1/calendar',
                                   data: 'people_id='+people_id+'&amp;title='+title+'&amp;start='+startdate+'&amp;end='+enddate,
                                  /*data: {  
                                      people_id:'people_id',
                                           title: 'title',
                                      start:'startdate',
                                      end:'enddate'
                                       },*/
                                   type: 'POST',
                                   dataType: 'json',
                                   success: function(response){
                                       bootbox.alert("Event Created!");
                                     //$('#calendar').fullCalendar('updateEvent',event);
                                     console.log(response);
                                   },
                                   error: function(e){
                                     console.log(e.responseText);
                                   }
                                 });  
  
                  }
              });
  
  
  
              //calendar.fullCalendar('unselect');
  
          }
          ,
          eventClick: function(calEvent, jsEvent, view) {
  
              var form = $("&lt;form class='form-inline'&gt;&lt;label&gt;Change event name &amp;nbsp;&lt;/label&gt;&lt;/form&gt;");
              form.append("&lt;input class='middle' autocomplete=off type=text value='" + calEvent.title + "' /&gt; ");
              form.append("&lt;button type='submit' class='btn btn-sm btn-success'&gt;&lt;i class='icon-ok'&gt;&lt;/i&gt; Save&lt;/button&gt;");
  
              var div = bootbox.dialog({
                  message: form,
                  buttons: {
                      "delete": {
                          "label": "&lt;i class='icon-trash'&gt;&lt;/i&gt; Delete Event",
                          "className": "btn-sm btn-danger",
                          "callback": function() {
                              calendar.fullCalendar('removeEvents', function(ev) {
                                  //alert("removed");
                                  //return (ev._id == calEvent._id);
                                  $.ajax({
                                      url: '/v1/calendar/'+event.event_id+'/destroy',
                                      data: 'type=remove&amp;eventid='+event.id,
                                      type: 'POST',
                                      dataType: 'json',
                                      success: function(response){
                                          console.log(response);
                                          if(response.status == 'success')
                                              jQuery('#calendar').fullCalendar('removeEvents', event.id);
                                      },
                                      error: function(e){ 
                                          alert('Error processing your request: '+e.responseText);
                                      }
                                  });
                              })
                          }
                      },
                      "close": {
                          "label": "&lt;i class='icon-remove'&gt;&lt;/i&gt; Close",
                          "className": "btn-sm"
                      }
                  }
  
              });
  
              form.on('submit', function(event) {
                  calEvent.title = form.find("input[type=text]").val();
                  calendar.fullCalendar('updateEvent', calEvent);
                  div.modal("hide");
  
                  //return false;
                  alert(event.event_id);
                $.ajax({
                      url: '/v1/calendar/'+event.event_id+'/update',
                      //data: 'title='+title+'&amp;eventid='+event.event_id,
                      data: {
                               title: 'title',
                               event_id: 'event_id'
                           },
                      type: 'POST',
                      dataType: 'json',
                      success: function(response){    
                          if(response.status == 'success')                            
                              $('#calendar').fullCalendar('updateEvent',event);
                              //alert("updated");
                              console.log(response);
                      },
                      error: function(e){
                          alert('Error processing your request: '+e.responseText);
                      }
  
                  });
  
  
  
              });
  
          }
  
  
      });
  
  
  });
  </code></pre>
  
  <p></p>
  
  <p>and this is my CalendarController.php file</p>
  
  <pre><code>    &lt;?php
  
  class CalendarController extends \BaseController {
  
  /**
   * Display a listing of calendar
   *
   * @return Response
   */
  public function index()
  {
      $event = DB::table('events')
  
      -&gt;leftJoin('people','people.people_id','=','events.people_id')  
      -&gt;leftJoin('people_roles','people_roles.people_id','=','events.people_id')      
      -&gt;get(array('people.address_id','people.people_id','people.occupation','people.firstname','people.lastname','people.comment','people.gender','people.middlename','people_roles.school_year','people_roles.teacher','people_roles.parent','people_roles.teacher_a_id','people_roles.admin','events.event_id','events.evt_description','events.date1','events.date2','events.time')); 
      //return View::make('people.show', compact('address'));
      return Response::json($event);
  }
  
  /**
   * Show the form for creating a new calendar
   *
   * @return Response
   */
  public function create()
  {
      return View::make('calendar.create');
  }
  
  /**
   * Store a newly created calendar in storage.
   *
   * @return Response
   */
  public function store()
  {
      $events= Input::get('type');
      $events= new Events;
      $events-&gt;people_id = Input::get('people_id');
      $events-&gt;evt_description =Input::get('title');
      $events-&gt;date1 =Input::get('start');
      $events-&gt;date2 =Input::get('end');
      //$events-&gt;time =Input::get('time');
  
      $events-&gt;save();
      //$validator = Validator::make($data = Input::all(), Events::$rules);
  
      /*if ($validator-&gt;fails())
      {
          return Redirect::back()-&gt;withErrors($validator)-&gt;withInput();
      }*/
      //Calendar::create($data);
      return Response::json($events);
      //return Redirect::route('calendar.index');
  }
  
  /**
   * Display the specified calendar.
   *
   * @param  int  $id
   * @return Response
   */
  public function show($id)
  {
      $calendar = Calendar::findOrFail($id);
  
      return View::make('calendar.show', compact('calendar'));
  }
  
  /**
   * Show the form for editing the specified calendar.
   *
   * @param  int  $id
   * @return Response
   */
  public function edit($id)
  {
      $calendar = Calendar::find($id);
  
      return View::make('calendar.edit', compact('calendar'));
  }
  
  /**
   * Update the specified calendar in storage.
   *
   * @param  int  $id
   * @return Response
   */
  public function update($id)
  {
      //$type=Input::get('type');
      $event_id= Input::get('event_id');
      $title= Input::get('title');
      $roles = DB::table('events')
                  -&gt;where('event_id','=',$event_id )
                  -&gt;update(array('evt_description' =&gt; $title));
  
       return Response::json(array('eventid'=&gt;$event_id,'title'=&gt;$title));
  
      /*$calendar = Calendar::findOrFail($id);
  
      $validator = Validator::make($data = Input::all(), Calendar::$rules);
  
      if ($validator-&gt;fails())
      {
          return Redirect::back()-&gt;withErrors($validator)-&gt;withInput();
      }
  
      $calendar-&gt;update($data);
  
      return Redirect::route('calendar.index');*/
  
  }
  
  /**
   * Remove the specified calendar from storage.
   *
   * @param  int  $id
   * @return Response
   */
  public function destroy()
  {
  //  Calendar::destroy($id);
  $event_id= Input::get('eventid');
  DB::table('events')-&gt;where('event_id','=',$event_id)-&gt;delete();
  
  return Response::json($event_id);
  
  //  return Redirect::route('calendar.index');
  }
  
  }
  </code></pre>
  
  <p>Please help me here folks...</p>