FullCalendar / Laravel JSON事件提要,找不到控制器路由问题

时间:2019-08-19 03:36:14

标签: json ajax laravel fullcalendar fullcalendar-4

我正在编写laravel应用程序,可以将FullCalendar与数据库集成。但是,当我放置JSON Event Feed URL时,出现内部服务器错误(500)。

我注意到该代码正在调用URL /getagenda.php?start=DATE/TIME&end=DATE/TIME,正如FullCalendar V4 Event JSON Feed Docs中所述。

相反,我想获得一个像127.0.0.1:8000/getagenda/{startParam}/{endParam}之类的“正常laravel路线”,或者一个没有任何参数的通用路线,这样我就可以正确访问控制器并获取事件的JSON数据。

我尝试了很多事情,但仍然无法解决...

错误:

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');

控制器:

 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 个答案:

答案 0 :(得分:0)

您有内部错误,因为您的服务器端控制器有错误

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

更改为

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

因为+仅可用于Javascript,但是在php中,必须使用.进行串联