Load events Fullcalendar Laravel JQuery

0

I am working with fullcalendar and laravel, I bring the data from the contractor, since they are shown in the console, but I can not make them appear in the calendar. This is my code:

routes.php

Route::get('events','EventsController@showEvents');

EventsController.php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\model\eventsModel;

class EventsController extends Controller
{

    public function showEvents(){
        $events = eventsModel::all();
        return response()->json($events);
    }
}

index.blade.html

$('#calendar').fullCalendar({

        businessHours: {
          // days of week. an array of zero-based day of week integers (0=Sunday)
          dow: [ 1, 2, 3, 4 ], // Monday - Thursday

          start: '10:00', // a start time (10am in this example)
          end: '19:00', // an end time (6pm in this example)
        },

          editable: true,
          header: {
              left: 'prev,next today',
              center: 'title',
              right: 'month,agendaWeek,agendaDay'
          },
          defaultView: 'agendaWeek',
          height: 500,
          slotMinutes: 15,
          loading: function(bool){
              if (bool) 
                  $('#loading').show();
              else 
                  $('#loading').hide();
          },

          minTime: '10:00',
          maxTime: '19:00',
          selectable: true,

          events: 
                $.ajax({

                       type:'get',
                       url:'events',
                       success: function (data)
                       {
                        console.log(data);
                          $('#calendar').fullCalendar({
                             events: data
                          });
                       }
                }),

I do not generate any errors, just do not show the events.

please suggestions thanks

    
asked by daniel2016. 08.06.2018 в 04:46
source

1 answer

0

It does not show you because you are not using ajax correctly, which according to the official documentation would be as follows :

$('#calendar').fullCalendar({
  businessHours: {
    // days of week. an array of zero-based day of week integers (0=Sunday)
    dow: [ 1, 2, 3, 4 ], // Monday - Thursday
    start: '10:00', // a start time (10am in this example)
    end: '19:00', // an end time (6pm in this example)
  },
  editable: true,
  header: {
    left: 'prev,next today',
    center: 'title',
    right: 'month,agendaWeek,agendaDay'
  },
  defaultView: 'agendaWeek',
  height: 500,
  slotMinutes: 15,
  loading: function(bool){
    if (bool) 
      $('#loading').show();
    else 
      $('#loading').hide();
  },
  minTime: '10:00',
  maxTime: '19:00',
  selectable: true,
  events: function(start, end, timezone, callback){
    $.ajax({
      type:'get',
      url:'events',
      success: function (data){
        callback(data);
      }
    })
  }
});
    
answered by 08.06.2018 в 04:59