0
votes

I am writing a laravel aplication, that I can integrate FullCalendar with a database. But when I put the JSON Event Feed URL, I get an internal server error (500).

I've noticed that the code is calling the URL /getagenda.php?start=DATE/TIME&end=DATE/TIME, just as described at FullCalendar V4 Event JSON Feed Docs.

Instead of this, I would like to get a "normal laravel route" like 127.0.0.1:8000/getagenda/{startParam}/{endParam}, or a common route without any parameters, so that I can properly acess my controller and get JSON Data of the events.

I've tried a lot of things, and still can't solve it...

Error:

Failed to load getagenda?start=2019-07-28T00%3A00%3A00-03%3A00&end=2019-09-08T00%3A00%3A00-03%3A00:1 resource: the server responded with a status of 500 (Internal Server Error)

Web.php:

Route::get('getagenda', 'App\AppointmentsController@indexshow')->name('agendashow');

Controller:

 public function indexshow(Request $request){
        $appointments = Appointment::all();
        $agenda = array();
        foreach ($appointments as $ap) {
            $e = array();
            $e['title'] = $ap->client->first_name + " " + $ap->client->last_name;
            $e['start'] = $ap->start_time;
            $e['end'] = $ap->finish_timet;
            $e['url'] = route('app.appointments.edit', $ap->id);

            array_push($agenda, $e);
          }   

        echo  json_encode($agenda);
    }

FullCalendar Js:

document.addEventListener('DOMContentLoaded', function() {
    var calendarEl = document.getElementById('calendar');

    var calendar = new Calendar(calendarEl, {
        plugins: [ dayGridPlugin ],
        locale: 'pt-br',
        events: {
            url: 'getagenda',
            failure: function() {
                alert('there was an error while fetching events!');
            }
          }
    });

    calendar.render();
  });
1

1 Answers

0
votes

You have internal error because you have an error in your server side controller

 $e['title'] = $ap->client->first_name + " " + $ap->client->last_name;

change to

  $e['title'] = $ap->client->first_name . " " . $ap->client->last_name;

because + can be only used in Javascript however in php you must use . for concatenation