【问题标题】:Laravel 5.1 FullCalendar tableLaravel 5.1 FullCalendar 表
【发布时间】:2016-04-13 20:02:47
【问题描述】:

我正在尝试使用这个包 https://github.com/maddhatter/laravel-fullcalendar 在我的 Laravel 项目中实现 FullCalendar 我已经创建了我的模型: EventModel.php

<?php

namespace App;
use Illuminate\Database\Eloquent\Model;
class EventModel extends Model implements \MaddHatter\LaravelFullcalendar\Event
{

    protected $dates = ['start', 'end'];

    /**
     * Get the event's id number
     *
     * @return int
     */
    public function getId() {
        return $this->id;
    }

    /**
     * Get the event's title
     *
     * @return string
     */
    public function getTitle()
    {
        return $this->title;
    }

    /**
     * Is it an all day event?
     *
     * @return bool
     */
    public function isAllDay()
    {
        return (bool)$this->all_day;
    }

    /**
     * Get the start time
     *
     * @return DateTime
     */
    public function getStart()
    {
        return $this->start;
    }

    /**
     * Get the end time
     *
     * @return DateTime
     */
    public function getEnd()
    {
        return $this->end;
    }
}

和我的控制器:

public function calendario() {
   $events = [];

    $events[] = \Calendar::event(
        'Event One', //event title
        false, //full day event?
        '2015-02-11T0800', //start time (you can also use Carbon instead of DateTime)
        '2015-02-12T0800', //end time (you can also use Carbon instead of DateTime)
        0 //optionally, you can specify an event ID
    );

    $events[] = \Calendar::event(
        "Valentine's Day", //event title
        true, //full day event?
        new \DateTime('2015-02-14'), //start time (you can also use Carbon instead of DateTime)
        new \DateTime('2015-02-14'), //end time (you can also use Carbon instead of DateTime)
        'stringEventId' //optionally, you can specify an event ID
    );

    $eloquentEvent = EventModel::first(); //EventModel implements MaddHatter\LaravelFullcalendar\Event

    $calendar = \Calendar::addEvents($events) //add an array with addEvents
        ->addEvent($eloquentEvent, [ //set custom color fo this event
            'color' => '#800',
        ])->setOptions([ //set fullcalendar options
            'firstDay' => 1
        ])->setCallbacks([ //set fullcalendar callback options (will not be JSON encoded)
            'viewRender' => 'function() {alert("Callbacks!");}'
        ]); 

    return view('hello', compact('calendar'));
}

但是当我去我的路线时我得到了这个错误:

SQLSTATE[42S02]:未找到基表或视图:1146 表 'petdate.event_models' 不存在(SQL: select * from event_models 限制 1)

我必须添加表格吗?

【问题讨论】:

  • 错误说必须存在一个表,所以是的,你必须添加一个表。
  • 但是表格需要哪些字段?

标签: php laravel eloquent fullcalendar laravel-5.1


【解决方案1】:

跟随你的心,不,我在开玩笑跟随你的模型功能:

protected $dates = ['start', 'end'];



 /**
     * Get the event's id number
     *
     * @return int
     */
    public function getId() {
        return $this->id;
    }

    /**
     * Get the event's title
     *
     * @return string
     */
    public function getTitle()
    {
        return $this->title;
    }

你可以看到你需要一个id和一个title,一个是int,另一个是string。 :)

【讨论】:

  • 谢谢
  • 告诉过你,我总是追随我的心,除了我的代码之外一切正常,但那是另一回事了。您随时欢迎。
猜你喜欢
  • 2015-12-14
  • 2020-09-20
  • 2015-10-25
  • 1970-01-01
  • 2017-01-13
  • 2016-12-10
  • 2015-10-28
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多