PHP code example of marshmallow / filament-fullcalendar
1. Go to this page and download the library: Download marshmallow/filament-fullcalendar 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/ */
marshmallow / filament-fullcalendar example snippets
namespace App\Filament\Widgets;
use Saade\FilamentFullCalendar\Widgets\FullCalendarWidget;
class CalendarWidget extends FullCalendarWidget
{
/**
* Return events that should be rendered statically on calendar.
*/
public function getViewData(): array
{
return [
[
'id' => 1,
'title' => 'Breakfast!',
'start' => now()
],
[
'id' => 2,
'title' => 'Meeting with Pamela',
'start' => now()->addDay(),
'url' => 'https://some-url.com',
'shouldOpenInNewTab' => true,
]
];
}
/**
* FullCalendar will call this function whenever it needs new event data.
* This is triggered when the user clicks prev/next or switches views on the calendar.
*/
public function fetchEvents(array $fetchInfo): array
{
// You can use $fetchInfo to filter events by date.
return [];
}
}
/**
* Consider this file the root configuration object for FullCalendar.
* Any configuration added here, will be added to the calendar.
* @see https://fullcalendar.io/docs#toc
*/
return [
'timeZone' => config('app.timezone'),
'locale' => config('app.locale'),
'headerToolbar' => [
'left' => 'prev,next today',
'center' => 'title',
'right' => 'dayGridMonth,dayGridWeek,dayGridDay'
],
'navLinks' => true,
'editable' => true,
'selectable' => false,
'dayMaxEvents' => true
];
/**
* Triggered when the user clicks an event.
*/
public function onEventClick($event): void
{
parent::onEventClick($event);
// your code
}
/**
* Triggered when dragging stops and the event has moved to a different day/time.
*/
public function onEventDrop($newEvent, $oldEvent, $relatedEvents): void
{
// your code
}
/**
* Triggered when event's resize stops.
*/
public function onEventResize($event, $oldEvent, $relatedEvents): void
{
// your code
}
public function createEvent(array $data): void
{
// Create the event with the provided $data.
}
public function getCreateEventModalTitle(): string
{
return __('filament::resources/pages/create-record.title', ['label' => $this->getModalLabel()]);
}
public function getCreateEventModalSubmitButtonLabel(): string
{
return __('filament::resources/pages/create-record.form.actions.create.label');
}
public function getCreateEventModalCloseButtonLabel(): string
{
return __('filament::resources/pages/create-record.form.actions.cancel.label');
}
public function editEvent(array $data): void
{
// Edit the event with the provided $data.
/**
* here you can access to 2 properties to perform update
* 1. $this->event_id
* 2. $this->event
*/
# $this->event_id
// the value is retrieved from event's id key
// eg: Appointment::find($this->event);
# $this->event
// model instance is resolved by user defined resolveEventRecord() funtion. See example below
// eg: $this->event->update($data);
}
// Resolve Event record into Model property
public function resolveEventRecord(array $data): Model
{
// Using Appointment class as example
return Appointment::find($data['id']);
}
public function getCreateEventModalTitle(): string
{
return __('filament::resources/pages/create-record.title', ['label' => $this->getModalLabel()]);
}
public function getEditEventModalSubmitButtonLabel(): string
{
return __('filament::resources/pages/edit-record.form.actions.save.label');
}
public function getEditEventModalCloseButtonLabel(): string
{
return $this->editEventForm->isDisabled()
? __('filament-support::actions/view.single.modal.actions.close.label')
: __('filament::resources/pages/edit-record.form.actions.cancel.label');
}
public static function canView(?array $event = null): bool
{
// When event is null, MAKE SURE you allow View otherwise the entire widget/calendar won't be rendered
if ($event === null) {
return true;
}
// Returning 'false' will not show the event Modal.
return true;
}
public static function canCreate(): bool
{
// Returning 'false' will remove the 'Create' button on the calendar.
return true;
}
public static function canEdit(?array $event = null): bool
{
// Returning 'false' will disable the edit modal when clicking on a event.
return true;
}
class CalendarWidget extends FullCalendarWidget
{
use CantManageEvents;
// ...
}
public function yourMethod(): void
{
$this->refreshEvents();
}
/**
* FullCalendar will call this function whenever it needs new event data.
* This is triggered when the user clicks prev/next or switches views.
*
* @see https://fullcalendar.io/docs/events-function
* @param array $fetchInfo start and end date of the current view
*/
public function fetchEvents(array $fetchInfo): array
{
return [];
}