PHP code example of team383 / livewire-resource-time-grid
1. Go to this page and download the library: Download team383/livewire-resource-time-grid 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/ */
team383 / livewire-resource-time-grid example snippets
public function resources()
{
// must return a Laravel collection
}
public function events()
{
// must return a Laravel collection
}
public function hourSlotClick($resourceId, $hour, $slot)
{
// This event is triggered when a time slot is clicked.//
// You'll get the resource id as well as the hour and minute
// clicked by the user
}
public function onEventClick($event)
{
// This event will fire when an event is clicked. You will get the event that was
// clicked by the user
}
public function onEventDropped($eventId, $resourceId, $hour, $slot)
{
// This event will fire when an event is dragged and dropped into another time slot
// You will get the event id, the new resource id + hour + minute where it was
// dragged to
}
public function isEventForResource($event, $resource)
{
// Must return true or false depending if the $resource is the owner of the $event
}
return $event['resource_id'] == $resource['id'];
@script
<script>
// This is ireResourceTimeGridMounted', () => {
initDragToScroll();
});
</script>
@endscript
// Render your component
@livewire(\App\Livewire\MyLivewireTimeGrid::class, [
...
'dragToScroll'=> true,
'dragToCreate' => true,
])
// You will need to load the relevant scripts after the component is initially rendered:
@livewireResourceTimeGridDragToScroll
@script
<script>
// This is
public function events()
{
return $itemCollection->map(fn (ItineraryItem $event) => [
# These items are standard as in the original package:
'id' => $event->id,
'resource_id' => intval($event->start_at->format('Ymd')),
'title' => $event->name,
'starts_at' => $event->start_at,
'ends_at' => $event->end_at,
# These are the additional properties we have added:
'header' => $event->start_at->format('H:i') . " - {$event->name}",
'header_class' => 'bg-blue-500 text-white p-1 text-xs font-bold',
'body' => $event->description,
'body_class' => 'bg-blue-100 p-1 text-xs whitespace-pre overflow',
'footer' => " ", # If this is empty, the footer won't be used, so we use a space to ensure it is rendered
'footer_class' => 'bg-blue-500 text-white p-1 text-xs font-bold',
]);
return $return;
}
bash
php artisan make:livewire AppointmentsGrid
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.