我试图从API获取事件,但这里发生了什么。 这是我在Angular项目中获取该事件的代码
this.calendarOptions = {
height: 'parent',
fixedWeekCount : false,
defaultDate: '2017-05-01',
editable: true,
eventLimit: true, // allow "more" link when too many events
events : function(start, end, timezone, callback) {
$.ajax({
url: 'http://localhost:8000/api/event/show',
dataType: 'json',
data: {
// our hypothetical feed requires UNIX timestamps
start: start.unix(),
end: end.unix()
},
success: function(data) {
var events = data;
callback(events);
}
});
}
这是我从数据库获取这些事件的查询 这是模型
public static function eventLists($start_date, $end_date){
return DB::table('event')
->select(DB::raw('name as title'),
DB::raw('DATE(start_time) as start'),
DB::raw('DATE(end_time) as end'))
->whereBetween(DB:raw($start_date, $end_date))
->get();
}
这是我的控制器
> public function showEvent(Request $request){
/**
* get query string
* get array data [start, end]
*/
$queryString = $request->all();
$start_date = date("Y-m-d",$queryString['start']);
$end_date = date("Y-m-d",$queryString['end']);
$data = EventModel::eventLists($start_date, $end_date);
$data = $data;
// $data = [ 'data' => $data ];
return response()->json($data)->withHeaders([
'Access-Control-Allow-Origin' => '*',
'Access-Control-Allow-Headers' => 'X-Requested-With, Content-Type, Accept, Origin, Authorization',
'Access-Control-Allow-Methods' => 'GET, POST, PUT, DELETE, OPTIONS'
]);
}
答案 0 :(得分:0)
public static function eventLists($start_date, $end_date){
return DB::table('event')
->select(DB::raw('name as title'),
DB::raw('DATE(start_time) as start'),
DB::raw('DATE(end_time) as end'))
->whereBetween('start', array($start_date, $end_date))
->get();
}