Fullcalendar - Can we add custom data to our event Json Data?

前端 未结 5 1129
逝去的感伤
逝去的感伤 2021-01-11 19:55

I want to send a type in my Event Json Response.

Here is my code:

$(\'#calendar\').fullCalendar({

eventSources: [ 

{\"id\":\"46_l\",\"title\":\"Cus         


        
5条回答
  •  南笙
    南笙 (楼主)
    2021-01-11 21:00

    You can also pass url endpoint to events as long as the url returns json response

                cId.fullCalendar({
                 header: {
                    right: '',
                    center: 'prev, title, next',
                    left: ''
                 },
    
                theme: true, //Do not remove this as it ruin the design
                selectable: true,
                selectHelper: true,
                editable: true,
                 //it will load data from this url
                events: "{{ url('api/events') }}",
    //               events: getData(),
    
                //Add Events
            });
    

    and in your controller or function

      $events = $request->user()->events()->select('title','color','date')->get();
    
       //        dd($even,$events)
              $eventsResponse = [];
     //        created_at->format('Y-m-d')
              foreach ($events as $event)
              {
               $eventsResponse[] = [
                'title'=>$event->title,
                'color'=>$event->color,
                'start'=> Carbon::parse($event->date)->toDateTimeString(),
               ];
            }
    
           return $eventsResponse;
    

提交回复
热议问题