我在laravel 5是个新手,我一直在按照github上的说明安装完整的日历(声明时间:https://github.com/maddhatter/laravel-fullcalendar
目前我只想在我的网站上显示日历,所以我做了以下操作:
通过composer安装了插件:“composer require maddhatter/laravel fullcalendar”&在我的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'));

}

这样做之后,is在说明中说,我必须将以下内容添加到我的视图中(在我的文件夹中:resources/pages/calendar.blade.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 install fullcalendar”。
另外,这是我的文件夹结构,因为我可能遗漏了一些内容:
在执行完所有这些步骤之后,它会显示日历,但我得到了这个错误:
可能是我太笨了,但我该怎么解决呢?

最佳答案

你最终成功了吗?
我只是在实现自己的时候遇到了一些问题,我想我会在解决这个问题的过程中增加我的经验。
这对我在Fedora上使用Laravel5.1和MySQL(Mariadb)起到了作用。
模型如下所示(从https://github.com/maddhatter/laravel-fullcalendar复制),更改了
类eventmodel扩展了雄辩的实现
\ maddhatter\laravelfullcalendar\event

类eventmodel扩展模型实现
\ maddhatter\laravelfullcalendar\event
向控制器添加了以下行
使用app\eventmodel;使用maddhatter\laravelfullcalendar\event;
对于db事件,在控制器中添加这个

$event = EventModel::all();

foreach ($event as $eve) {
  $events[] = \Calendar::event(
  $eve->title, //event title
  $eve->allDay, //full day event?
  $eve->start, //start time (you can also use Carbon instead of DateTime)
  $eve->end, //end time (you can also use Carbon instead of DateTime)
  $eve->id //optionally, you can specify an event ID
  );
}

如果使用blade模板,我必须将脚本添加到母版页和日历页(如果从母版页和日历页中删除,则不会显示日历)
肮脏的简易路线
route::resource('calendar','calendarcontroller');
我是新来的拉勒维尔,所以我知道可能有更简单的方法,或者我没有遵循惯例,但这是我如何让它工作到目前为止,希望它有帮助。

09-19 16:16