Showing events from MySQL database on Vue.js Fullcalendar

I am trying to fetch events from my MySQL database and pass them to my Vue component to be displayed on the FullCalendar. However, the event array is being populated with a full HTML document.

Below is my EventController:

public function getEvents()
{
    $getEvents = Event::query()->select('projectid','event_id','start_time','end_time','notes','taskid')->get();
    $events = [];

    foreach ($getEvents as $values) {
       $event = [];
       $event['eventid'] = $values->event_id;
       $event['projectid'] = $values->projectid;
       $event['start_time'] = $values->start_time;
       $event['end_time'] = $values->end_time;
       $event['notes'] = $values->notes;
       $event['taskid'] = $values->taskid;
       $events[] = $event;
    }
    return json_encode($events);
}

My FullCalendar.vue Component:

<template>
  <FullCalendar
      ref="fullCalendar"
      :options="calendarOptions"
      color="primary"
      :events="getEvents"
      :type="type"
      v-model="query"
  ></FullCalendar>
</template>

<script>
import FullCalendar from '@fullcalendar/vue'
import timeGridPlugin from '@fullcalendar/timegrid'
import interactionPlugin from '@fullcalendar/interaction'
import axios from 'axios'

export default {
  components: {
    FullCalendar // make the <FullCalendar> tag available
  },
  props: {},
  data() {
    return {
      events: [],
      calendarOptions: {
        plugins: [timeGridPlugin, interactionPlugin],
        initialView: 'timeGridWeek',
        weekends: false,
        eventClick: this.handleEventClick,

      },

    }
  },
  computed: {},
  methods: {
    handleEventClick: function (arg) {
      alert('Event: ' + arg.events);
    },
    getEvents: function () {
      this.$http.get('/events', {data: {query: this.query}}).then((response) => {
        this.events = response.data;
        console.log(this.events);
      }, (error) => {
      })
    }
  },
  mounted() {
    this.getEvents();
  },
}
</script>

<style scoped>

</style>

My Routes:

Route::get('/events', 'EventController@getEvents')->name('event.getEvents');

My blade.php:

    <v-card>
        <v-layout row wrap>
            <v-flex>
                <v-btn color="primary" dark @click="newEventDialog = true">
                    New Event
                </v-btn>
                <full-calendar></full-calendar>
            </v-flex>
        </v-layout>
    </v-card>

This is what is currently being populated in my events array:

"<!DOCTYPE html>\r\n<html lang=\"en\">\r\n<head>\r\n    <meta charset=\"utf-8\">\r\n    <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\r\n  .........

Answer №1

The problem stemmed from having a conflicting route named Route('/event'). Another route with the same name was already in existence.

Below is the code snippet to fetch events and showcase them on the calendar at https://fullcalendar.io.

Route:

Route::get('/event', 'EventController@getEvents');

EventController:

 public function getEvents()
    {
         $getEvents = Event::query()->select('projectid',
            'eventid',
            'start_time',
            'end_time',
            'notes',
            'taskid')
            ->get();

        $events = [];

        foreach ($getEvents as $values) {
            $event = [];
            $startTime = Carbon::parse($values->start_time)->format("Y-m-d H:s");
            $endTime = Carbon::parse($values->end_time)->format("Y-m-d H:s");
            $startTime = Carbon::parse($startTime)->timezone("Africa/Windhoek");
            $endTime = Carbon::parse($endTime)->timezone("Africa/Windhoek");

            $values->start_time = $startTime;
            $values->end_time = $endTime;

            $event['id'] = $values->eventid;
            $event['title'] = $values->notes;
            $event['start'] = $values->start_time;
            $event['end'] = $values->end_time;
            $event['allDay'] = false;
            $events[] = $event;
        }

        return response()->json($events);
    }

FullCalendar.vue

<template>
  <FullCalendar ref="fullCalendar" :options="calendarOptions" :events="event"/>
</template>
<script>
import FullCalendar from '@fullcalendar/vue'
import timeGridPlugin from '@fullcalendar/timegrid'
import interactionPlugin from '@fullcalendar/interaction'
import axios from 'axios'
export default {
  components: {
    FullCalendar
  },
  props: {},
  data() {
    return {
      calendarOptions: {
        plugins: [timeGridPlugin, interactionPlugin],
        initialView: 'timeGridWeek',
        weekends: false,
        editable:true,
        eventClick: this.handleEventClick,
        dateClick:this.handleDateClick,
        events: []
      },
    }
  },
  computed: {},
  methods: {
    handleEventClick: function (arg) {
      alert('Event' + event.title)
    },
    handleDateClick: function (arg) {
    },
    getEvents: function () {
      this.$http.get('/event').then((response) => {
        console.log(response);
        this.calendarOptions.events = response.data;
      }, (error) => {
      })
    }
  },
  mounted() {
    this.events = this.getEvents();
  },
}
</script>

<style scoped>
</style>

home.blade.php

     <v-card>
        <v-layout row wrap>
            <v-flex>
                <full-calendar></full-calendar>
            </v-flex>
        </v-layout>
    </v-card>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Avoiding Ajax overload/server collapse in an Arduino/ESP8266 setting

I've recently been delving into Arduino programming to host an HTML/CSS/JavaScript webpage on an Adafruit HUZZAH ESP8266 breakout board. Please pardon any unconventional methods I may be using. My approach involves utilizing Ajax to update pressure g ...

An easy way to attach a Contextmenu to a specific element

I have implemented a scrolling feature for one of the div elements in my Application. Inside this div, there is a templated table with over 100 rows. Users are able to add or delete rows using a contextMenu. The contextMenu offers 4 options - AddTop, AddB ...

Choose the identical document within the Vuetify part v-file-input

I am currently working on a web application using nuxt, vuetify 2.x, and typescript. One issue I am facing is with uploading files using v-file-input. Specifically, if I select a file and then close the dialog without saving it, I am unable to select that ...

What is the best way to choose the final index value in a drop-down menu?

Is there a way to read and select the last index value in a drop-down using JavaScript? Here is an example of the HTML code: <select name="unqiue"> <option value="number:1" label="1">1</option> <option value="number:2" label="2" ...

"Looping through each item in a list using Angular

I have a setup for an HTTP request that will return the list of products once all promises are fulfilled. My objective is to initially set the opacity of these products to 0, and then use a forEach loop to add a class that sets their opacity to 1. While ...

Troubles encountered while deploying Vue.js application using IBM Cloud and Cloud Foundry Node Buildpack

I am completely new to using IBM Cloud for the first time and need some assistance. I am looking to deploy my Vue.js app on IBM Cloud with continuous delivery. The Vue project is stored in a GitHub repository, and I want it to be deployed automatically whe ...

In a peculiar occurrence, the behavior of array.splice is exhibiting unusual characteristics within an

Be sure to take a look at this plunkr for reference: http://plnkr.co/edit/FQ7m6HPGRrJ80bYpH8JB?p=preview I'm encountering an issue where, after adding an element and then deleting it from the array using the splice method, everything becomes disorg ...

How can we efficiently save multiple IDs from table B into table A in SQL?

Hello, I am currently a student focusing on SQL and working with two tables: Student and Subjects. -Student(ID,name,subjects) (1,testing,here is the id of multiple subject) -Subjects (ID,name,Desc) (1,Subject1,somedesc) (2,Subject2,somedesc) (3,Subject3, ...

Add a dynamic widget to a specific element in the document object model in real time

Is there a way to dynamically create a jQuery UI widget using a string? You can easily do this by following the example below: $(function() { $("selector").widget() }) However, what I am trying to accomplish is slightly different. Here is an examp ...

Toggle textboxes using jQuery depending on the radio button choice

I'm trying to make specific textboxes appear when a particular radio button is clicked on my form, but I want them to remain hidden otherwise. Here's an example of what I've implemented: HTML: Radio buttons: <p>Show textboxes<inpu ...

Include dropdown lists for selecting the year, month, and day on a web page

Is there a way to implement a dropdown style date selector that dynamically updates the number of days based on the selected year and month using JavaScript? For example, February 2008 has 29 days, April has 30 days, and June has 31 days. Any suggestions ...

Exploring Laravel by running diverse code on a shared database

I am currently in the process of transitioning my application from a custom framework to Laravel, and I am trying to plan how I will approach testing in Laravel going forward. Currently, my testing setup involves: I have my application split into two fol ...

Error: The "map" property cannot be read if it is undefined in a Django and React application

While I was following the react and django tutorial, I encountered an issue when I added some code for concern with. The error message 'Cannot read property 'map' of undefined' keeps getting thrown. The error location is pointed out ...

Tips for capturing the datePicker closing event

Currently, I have successfully implemented a date picker on my website. In some sections of my page, there is a requirement for calculating values based on the start and end dates selected by the user. However, I am facing an issue where I am unable to per ...

Can we enhance the efficiency of this equation?

The formula provided organizes the elements in the container based on mouse movement. The issue stemmed from the image size and the different calculations performed when approaching along the x and y axes from various directions. const zoomEffect = (even ...

Analyzing objects within an array for similarities

Suppose I have an array containing objects: var arr = [ { id: 1, pt: 0 }, { id: 2, pt: 12 }, { id: 3, pt: 7 }, { id: 4, pt: 45 }, { id: 5, pt: 123 }, ]; I am looking to loop through this array (possibly using array.forEach or array.map) ...

Encountering problems with Nuxt/Vue hydration when utilizing a slotted component

Recently, in my new Nuxt project, I have been facing some peculiar hydration problems. Despite putting effort into isolating the issue and providing a demonstration (refer to the image), the hydration error seems to occur unpredictably. Is there anyone ou ...

Creating a personalized progress bar that reflects real-time data from an external API

I have developed an API that sends scores if someone solves math, chemistry, or physics problems correctly. The API responds with a JSON object like this: { "scores": { "maths": 28, "chemistry": 9, "physics": 26, } } When a person complet ...

Iterating through the startPrivateConversation method in Botkit for a multitude of users

In order to send an update to all my users, I created a new bot controller in a separate js file. To achieve this successfully, I needed to implement a notification function inside the controller's rtm_open function. The goal was to iterate through th ...

What could be causing my select tags to appear incorrectly in Firefox and IE?

With the help of Jquery, my goal is to dynamically populate a select field when it is in focus, even if it already has a value. Once populated, I want to retain the previous value if it exists as an option in the newly populated field. Although this works ...