The provider and Calendar alias will be registered automatically.
You will also need to include fullcalendar.io's files in your HTML.
Usage
Creating Events
Using event():
The simpliest way to create an event is to pass the event information to Calendar::event():
$event = \Calendar::event(
"Valentine's Day", //event titletrue, //full day event?'2015-02-14', //start time, must be a DateTime object or valid DateTime format (http://bit.ly/1z7QWbg)'2015-02-14', //end time, must be a DateTime object or valid DateTime format (http://bit.ly/1z7QWbg),1, //optional event ID
[
'url' => 'http://full-calendar.io'
]
);
Implementing Event Interface
Alternatively, you can use an existing class and have it implement MaddHatter\LaravelFullcalendar\Event. An example of an Eloquent model that implements the Event interface:
classEventModelextendsEloquentimplements \MaddHatter\LaravelFullcalendar\Event
{
protected$dates = ['start', 'end'];
/** * Get the event's id number * * @return int */publicfunctiongetId() {
return$this->id;
}
/** * Get the event's title * * @return string */publicfunctiongetTitle()
{
return$this->title;
}
/** * Is it an all day event? * * @return bool */publicfunctionisAllDay()
{
return (bool)$this->all_day;
}
/** * Get the start time * * @return DateTime */publicfunctiongetStart()
{
return$this->start;
}
/** * Get the end time * * @return DateTime */publicfunctiongetEnd()
{
return$this->end;
}
}
IdentifiableEvent Interface
If you wish for your existing class to have event IDs, implement \MaddHatter\LaravelFullcalendar\IdentifiableEvent instead. This interface extends \MaddHatter\LaravelFullcalendar\Event to add a getId() method:
classEventModelextendsEloquentimplements \MaddHatter\LaravelFullcalendar\IdentifiableEvent
{
// Implement all Event methods .../** * Get the event's ID * * @return int|string|null */publicfunctiongetId();
}
Pass an array of 'parameter' => 'value' pairs as the 6th parameter to Calendar::event():
$event = \Calendar::event(
"Valentine's Day", //event titletrue, //full day event?'2015-02-14', //start time, must be a DateTime object or valid DateTime format (http://bit.ly/1z7QWbg)'2015-02-14', //end time, must be a DateTime object or valid DateTime format (http://bit.ly/1z7QWbg),1, //optional event ID
[
'url' => 'http://full-calendar.io',
//any other full-calendar supported parameters
]
);
To create a calendar, in your route or controller, create your event(s), then pass them to Calendar::addEvent() or Calendar::addEvents() (to add an array of events). addEvent() and addEvents() can be used fluently (chained together). Their second parameter accepts an array of valid FullCalendar Event Object parameters.
Sample Controller code:
$events = [];
$events[] = \Calendar::event(
'Event One', //event titlefalse, //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 titletrue, //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'));
Sample View
Then to display, add the following code to your View:
Note: The output from calendar() and script() must be non-escaped, so use {!! and !!} (or whatever you've configured your Blade compiler's raw tag directives as).
The script() can be placed anywhere after calendar(), and must be after fullcalendar was included.
请发表评论