【问题标题】:The event show in continuous date活动日期连续显示
【发布时间】:2017-05-10 08:45:02
【问题描述】:

我试图从 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'
    ]);

}

【问题讨论】:

  • 到底是什么问题?
  • 问题是在连续日期中显示的事件。该事件应显示在给定的日期。这是我的数据库中的示例数据
  • @theZaki [{title: "aly day", start: "2017-04-01", end: "2017-04-06"},…] 0 : {title: "aly day ", start: "2017-04-01", end: "2017-04-06"} 1 : {title: "团队午餐", start: "2017-04-05", end: "2017-04-06 "} 2 : {title: "团队建设", start: "2017-04-01", end: "2017-04-01"} 3 : {title: "test", start: "2017-04-05" , end: "2017-04-06"} 4 : {title: "jen day", start: "2017-01-19", end: "2017-05-01"}
  • 查询必须SELECT名称、开始、结束FROM事件WHEREstart_timeBETWEEN($start_date, $end_date)
  • @bluehipy 是的,我试图这样做,但我的查询有问题。它给了我一个错误 ->whereBetween((DB:raw($start_date, $end_date))

标签: javascript angular lumen


【解决方案1】:
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();

 }

【讨论】:

  • 现在可以工作了。谢谢你的帮助。有一个好的:)))))))
  • 祝你的项目好运 ;)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2023-03-07
  • 2021-08-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多