Laravel FullCalendar.io Helper
For Laravel 4.2: use the laravel-4 branch
This is a simple helper package to make generating http://fullcalendar.io in Laravel apps easier.
Require the package with composer using the following command:
composer require maddhatter/laravel-fullcalendarOr add the following to your composer.json's require section and composer update
"require": {
"maddhatter/laravel-fullcalendar": "~1.0"
}Register the service provider in your app.php config file:
MaddHatter\LaravelFullcalendar\ServiceProvider::class,And optionally create an alias:
'Calendar' => MaddHatter\LaravelFullcalendar\Facades\Calendar::class,
The provider and Calendar alias will be registered automatically.
You will also need to include fullcalendar.io's files in your HTML.
event():The simpliest way to create an event is to pass the event information to Calendar::event():
$event = \Calendar::event(
"Valentine's Day", //event title
true, //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'
]
);Event InterfaceAlternatively, you can use an existing class and have it implement MaddHatter\LaravelFullcalendar\Event. An example of an Eloquent model that implements the Event interface:
…IdentifiableEvent InterfaceIf 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:
class EventModel extends Eloquent implements \MaddHatter\LaravelFullcalendar\IdentifiableEvent
{
// Implement all Event methods ...
/**
* Get the event's ID
*
* @return int|string|null
*/
public function getId();
}
If you want to add additional parameters to your events, there are two options:
Calendar::event()Pass an array of 'parameter' => 'value' pairs as the 6th parameter to Calendar::event():
$event = \Calendar::event(
"Valentine's Day", //event title
true, //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
]
);
getEventOptions method to your event class $this->background_color,
//etc
];
}
//...
}
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.
…Then to display, add the following code to your View:
{!! $calendar->calendar() !!}
{!! $calendar->script() !!}
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.
This will generate (in February 2015):
No open issues yet, or sync has not completed.