1. Go to this page and download the library: Download guava/calendar library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
guava / calendar example snippets
use \Guava\Calendar\Widgets\CalendarWidget;
class MyCalendarWidget extends CalendarWidget
{
}
Event::make()->styles([
'color: red' => true, // Applies the style if the condition (true) is met
'background-color' => '#ffff00', // Directly applies the background color
'font-size: 12px' // Always applies this font size
]);
Event::make()->classNames([
'class-1',
'class-2' => true // Applies the class if the condition (true) is met
]);
Event::make()
->display('background') // or 'auto'
->displayAuto() // short-hand for ->display('auto')
->displayBackground(); // short-hand for ->display('background')
public function getEventContent(): null|string|array
{
// return a blade view
return view('calendar.event');
// return a HtmlString
return new HtmlString('<div>My event</div>');
}
public function getEventContent(): null|string|array
{
return [
MyModel::class => view('calendar.my-model-event'),
AnotherModel::class => view('calendar.another-model-event'),
];
}
public function getResourceLabelContent(): null|string|array
{
// return a blade view
return view('calendar.resource');
// return a HtmlString
return new HtmlString('<div>My resource</div>');
}
public function getSchema(?string $model = null): ?array
{
// If you only work with one model type, you can ignore the $model parameter and simply return a schema
return [
TextInput::make('title')
];
// If you have multiple model types on your calendar, you can return different schemas based on the $model property
return match($model) {
Foo::class => [
TextInput::make('name'),
],
Bar::class => [
TextInput::make('title'),
TextArea::make('description'),
],
}
}
public function getResources(): Collection|array
{
return [
// Chainable object-oriented variant
Resource::make('foo')
->title('Room 1'),
// Array variant
['id' => 'bar', 'title' => 'Room 2'],
// Eloquent model implementing the `Resourceable` interface
MyRoom::find(1),
];
}
public function onEventClick(array $info = []): void
{
// do something on click
// $info contains the event data:
// $info['event'] - the event object
// $info['view'] - the view object
}
protected bool $eventResizeEnabled = true;
public function onEventResize(array $info = []): bool
{
// Don't forget to call the parent method to resolve the event record
parent::onEventResize($info);
// Validate the data
// Update the record ($this->getEventRecord())
// $info contains the event data:
// $info['event'] - the event object
// $info['oldEvent'] - the event object before resizing
// $info['endDelta'] - the difference in time between the old and new event
// Return true if the event was resized successfully
// Return false if the event was not resized and should be reverted on the client-side
}
protected bool $eventDragEnabled = true;
public function onEventDrop(array $info = []): bool
{
// Don't forget to call the parent method to resolve the event record
parent::onEventDrop($info);
// Validate the data
// Update the record ($this->getEventRecord())
// $info contains the event data:
// $info['event'] - the event object
// $info['oldEvent'] - the event object before resizing
// $info['oldResource'] - the old resource object
// $info['newResource'] - the new resource object
// $info['delta'] - the duration object representing the amount of time the event was moved by
// $info['view'] - the view object
// Return true if the event was moved successfully
// Return false if the event was not moved and should be reverted on the client-side
}
protected bool $dateClickEnabled = true;
public function onDateClick(array $info = []): bool
{
// Validate the data
// $info contains the event data:
// $info['date'] - the date clicked on
// $info['dateStr'] - the date clicked on as a UTC string
// $info['allDay'] - whether the date is an all-day slot
// $info['view'] - the view object
// $info['resource'] - the resource object
}
protected bool $dateSelectEnabled = true;
public function onDateSelect(array $info = []): bool
{
// Validate the data
// $info contains the event data:
// $info['start'] - the start date of the range
// $info['startStr'] - the start date as an UTC string
// $info['end'] - the end date of the range
// $info['endStr'] - the end date as an UTC string
// $info['allDay'] - whether the date is an all-day slot
// $info['view'] - the view object
// $info['resource'] - the resource object
}
protected bool $noEventsClickEnabled = true;
public function onNoEventsClick(array $info = []): void
{
// do something on click
// $info contains the event data:
// $info['view'] - the view object
}