1. Go to this page and download the library: Download da-sie/livewire-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/ */
da-sie / livewire-calendar example snippets
use Asantibanez\LivewireCalendar\LivewireCalendar;
use Illuminate\Support\Collection;
use Carbon\Carbon;
class AppointmentsCalendar extends LivewireCalendar
{
public function events(): Collection
{
return collect([
[
'id' => 1,
'title' => 'Breakfast',
'description' => 'Pancakes!',
'date' => Carbon::today(),
],
[
'id' => 2,
'title' => 'Meeting',
'description' => 'Work stuff',
'date' => Carbon::tomorrow(),
],
]);
}
}
public function onDayClick($year, $month, $day)
{
// Triggered when a day cell is clicked
}
public function onEventClick($eventId)
{
// Triggered when an event is clicked
}
public function onEventDropped($eventId, $year, $month, $day)
{
// Triggered when an event is dragged and dropped to another day
// $year/$month/$day = target day
}
use Livewire\Attributes\On;
#[On('calendar-event-dropped')]
public function handleEventDrop($eventId, $targetYear, $targetMonth, $targetDay, $sourceYear, $sourceMonth, $sourceDay)
{
$event = Event::find($eventId);
// Calculate how many days the event was moved
$source = Carbon::create($sourceYear, $sourceMonth, $sourceDay);
$target = Carbon::create($targetYear, $targetMonth, $targetDay);
$diff = $source->diffInDays($target, false);
// Shift both start and end dates by the same offset
$event->update([
'date' => Carbon::parse($event->date)->addDays($diff),
'date_end' => $event->date_end ? Carbon::parse($event->date_end)->addDays($diff) : null,
]);
}