dongmei8209 2019-03-22 16:32
浏览 228

将事件从表显示为fullcalendar

I am trying to implement an event calendar inside one of my vue components in Laravel but I am not able to display the events on the calendar from my SQL database. Although, I am able to view the columns of my table using my resource controller. Note:- I am using router-view to display all the content under the id content so there are no blade templates. Any help please!! Thanks in advance.

Dashboard.vue
<template>
<full-calendar :config='config'>
</full-calendar>
</template>
<script>
export default{
 data() {
    return {
      config: {
        defaultView: "month"
      },
methods:{
loadEvents() {
      axios.get("api/event").then(({ data }) => (this.events = data));
    }
},
created(){
this.loadEvents();
}
};
</script>
Controller type:resource

public function index()
    {

            $events = DB::table('events')->get();
            $event = [];

            foreach($events as $row){
                $endDate = $row->end_date."24:00:00";
                $event[] = \Calendar::event(
                    $row->event_title,
                    true,
                    new \DateTime($row->start_date),
                    new \DateTime($row->end_date),
                    $row->id,
                    [
                        'color'=>$row->color,
                    ]
                    );
            }
            $calendar =  \Calendar::addEvents($event);
            return $events;


    }

class CreateEventsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('events', function (Blueprint $table) {
            $table->increments('id');
            $table->integer('user_id')->unsigned();
            $table->foreign('user_id')->references('id')->on('users');
            $table->string('event_title');
            $table->string('event_description');
            $table->string('color');
            $table->datetime('start_date');
            $table->datetime('end_date');
            $table->timestamps();
        });
    }
};
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 lammps拉伸应力应变曲线分析
    • ¥15 C++ 头文件/宏冲突问题解决
    • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
    • ¥50 安卓adb backup备份子用户应用数据失败
    • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
    • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
    • ¥30 python代码,帮调试
    • ¥15 #MATLAB仿真#车辆换道路径规划
    • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
    • ¥15 数据可视化Python