我在Laravel 5非常新,我一直在尝试按照Github的说明来安装完整的日历(在:https://github.com/maddhatter/laravel-fullcalendar上)
目前,我只想在我的网站上显示日历,所以我做了以下工作:
通过composer安装插件:“composer需要maddhatter/laravel-完全日历”&在我的app.php中添加了一个别名。
接下来,我创建了一个接口,它扩展了像这样的雄辩\模型:(当我将事件添加到数据库时):
<?php namespace App;
use Illuminate\Database\Eloquent\Model;
class EventModel extends Model \MaddHatter\LaravelFullcalendar\IdentifiableEvent{
//fillable = Being able to mass assign (MassAssignment exception)
protected $dates = ['start', 'end'];
/**
* Get the event's id number
*
* @return int
*/
public function getId();
/**
* 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;
}
}然后在我的控制器里我补充道:
<?php namespace App\Http\Controllers;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
class CalendarController extends Controller {
$events[] = \Calendar::event(
'Event One', //event title
false, //full day event?
'2015-06-05T0800', //start time (you can also use Carbon instead of DateTime)
'2015-06-05T0800', //end time (you can also use Carbon instead of DateTime)
0 //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('pages.calendar', compact('calendar'));
}完成此操作后,在说明中说明我必须将以下内容添加到我的视图中(在我的文件夹中:resources/page/caltim.blde.php):
@extends('masterpage')
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/moment.js/2.9.0/moment.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/fullcalendar/2.2.7/fullcalendar.min.js"></script>
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/fullcalendar/2.2.7/fullcalendar.min.css"/>
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/fullcalendar/2.2.7/fullcalendar.print.css"/>
@section('content')
<h1> Calendar </h1>
{!! $calendar->calendar() !!}
{!! $calendar->script() !!}
@stop我还在我的项目中做了“$bower安装完整日历”来添加它们。
另外,这是我的文件夹结构,因为我可能遗漏了一些东西:

在执行了所有这些步骤之后,它说日历应该显示,但是我得到了这个错误:

可能是我太蠢了,但我该怎么解决呢?
发布于 2015-09-23 02:58:04
你最终成功了吗?
我只是在实现自己的时候遇到了一些问题,我想我应该在解决这个问题上增加我的经验。
对于我来说,使用Laravel5.1和mysql (mariadb)在fedora上是可行的。
类EventModel扩展了雄辩的实现\MaddHatter\LaravelFullcalendar\事件
至
类EventModel扩展模型实现\MaddHatter\LaravelFullcalendar\事件
使用App\EventModel;使用MaddHatter\LaravelFullcalendar\Event;
$event = EventModel::all();foreach ($event as $eve) { $events[] = \Calendar:: event ( $eve-> title,//event title $eve->allDay,//全天事件?$eve>start,//start time (也可以使用碳代替DateTime) $eve>结束,//结束时间(您也可以使用碳代替DateTime) $eve> ID //可选,您可以指定事件ID );}
路线:资源(“日历”,“CalendarController”);
我是新来的拉拉,所以我知道可能有更容易的方式,或我没有遵守惯例,但这是我如何让它到目前为止,希望它有帮助。
发布于 2015-06-05 11:54:06
看起来控制器中的代码不是在一个方法中:
class CalendarController extends Controller {
public function index() { //code should be inside a method
$events[] = \Calendar::event(
'Event One', //event title
false, //full day event?
'2015-06-05T0800', //start time (you can also use Carbon instead of DateTime)
'2015-06-05T0800', //end time (you can also use Carbon instead of DateTime)
0 //optionally, you can specify an event ID
);
$eloquentEvent = EventModel::first(); //EventModel implements MaddHatter\LaravelFullcalendar\Event
$calendar = \Calendar::addEvents($events) //add an array with addEvents
->setOptions([ //set fullcalendar options
'firstDay' => 1
])->setCallbacks([ //set fullcalendar callback options (will not be JSON encoded)
'viewRender' => 'function() {alert("Callbacks!");}'
]);
return view('pages.calendar', compact('calendar'));
}
}更新:
您的EventModel的getId()方法也需要有body (即:它需要一个打开/关闭{和},并做一些事情):
/**
* Get the event's id number
*
* @return int
*/
public function getId() {
return $this->id;
}项目的readme.md缺少一个示例体。
更新2:
class EventModel extends Model \MaddHatter\LaravelFullcalendar\IdentifiableEvent应该是
class EventModel extends Model implements \MaddHatter\LaravelFullcalendar\IdentifiableEventhttps://stackoverflow.com/questions/30662238
复制相似问题