Laravel Livewire component to show Events in a good looking monthly calendar

Overview

Livewire Calendar

This package allows you to build a Livewire monthly calendar grid to show events for each day. Events can be loaded from within the component and will be presented on each day depending on the date of the event.

Preview

preview

Installation

You can install the package via composer:

composer require asantibanez/livewire-calendar

Requirements

This package uses livewire/livewire (https://laravel-livewire.com/) under the hood.

It also uses TailwindCSS (https://tailwindcss.com/) for base styling.

Please make sure you include both of this dependencies before using this component.

Usage

In order to use this component, you must create a new Livewire component that extends from LivewireCalendar

You can use make:livewire to create a new component. For example.

php artisan make:livewire AppointmentsCalendar

In the AppointmentsCalendar class, instead of extending from the base Component Livewire class, extend from LivewireCalendar. Also, remove the render method. You'll have a class similar to this snippet.

class AppointmentsCalendar extends LivewireCalendar
{
    //
}

In this class, you must override the following method

public function events() : Collection
{
    // must return a Laravel collection
}

In the events() method, return a collection holding the events that will be displayed on the calendar. Events must be keyed arrays holding at least the following keys: id, title, description, date (date must be a Carbon\Carbon instance).

Example

public function events() : Collection
{
    return collect([
        [
            'id' => 1,
            'title' => 'Breakfast',
            'description' => 'Pancakes! 🥞',
            'date' => Carbon::today(),
        ],
        [
            'id' => 2,
            'title' => 'Meeting with Pamela',
            'description' => 'Work stuff',
            'date' => Carbon::tomorrow(),
        ],
    ]);
}

The date value will be used to determine to what day the event belongs to. To load values in the events() method, you can use the following component properties to filter your events.

  • startsAt: starting date of month
  • endsAt: ending date of month
  • gridStartsAt: starting date of calendar grid. Can be a date from the previous month.
  • endingStartsAt: ending date of calendar grid. Can be a date from the next month.

Example

public function events(): Collection
{
    return Model::query()
        ->whereDate('scheduled_at', '>=', $this->gridStartsAt)
        ->whereDate('scheduled_at', '<=', $this->gridEndsAt)
        ->get()
        ->map(function (Model $model) {
            return [
                'id' => $model->id,
                'title' => $model->title,
                'description' => $model->notes,
                'date' => $model->scheduled_at,
            ];
        });
}

Now, we can include our component in any view.

Example

<livewire:appointments-calendar/>

This will render a calendar grid.

example

By default, the component will render the current month. If you want to change the starting month, you can set the year and month props.

Example

<livewire:appointments-calendar
   year="2019"
   month="12"
/>

You should include scripts with @livewireCalendarScripts to enable drag and drop which is turned on by default. You must include them after @livewireScripts

@livewireScripts
@livewireCalendarScripts

The component has 3 public methods that can help navigate forward and backward through months:

  • goToPreviousMonth
  • goToNextMonth
  • goToCurrentMonth

You can use these methods on extra views using before-calendar-view or after-calendar-view explained below.

Advanced usage

Ui customization

You can customize the behavior of the component with the following properties when rendering on a view:

  • week-starts-at which can be a number from 0 to 6 according to Carbon days of week to indicate with which day of week the calendar should render first.

  • event-view which can be any blade.php view that will be used to render the event card. This view will be injected with a $event variable holding its data.

  • before-calendar-view and after-calendar-view can be any blade.php views that can be rendered before or after the calendar itself. These can be used to add extra features to your component using Livewire.

  • drag-and-drop-classes can be any css class used to render the hover effect when dragging an event over each day in the calendar. By default, this value is border border-blue-400 border-4

  • day-of-week-view which can be any blade.php view that will be used to render the header of each calendar day. This view will be injected the day property which is a Carbon instance of the day of the week.

<livewire:appointments-grid
    week-starts-at="0, 1, 2, 3, 4, 5 or 6. 0 stands for Sunday"
    event-view="path/to/view/starting/from/views/folder"
    day-of-week-view="path/to/view/starting/from/views/folder"
    before-calendar-view="path/to/view/starting/from/views/folder"
    after-calendar-view="path/to/view/starting/from/views/folder"
    drag-and-drop-classes="css classes"
/>

Advanced ui customization

(This options should be used using blade views based on the component default views)

To use these options, it is recommended to publish the base blade views used by the component and extend their behavior and styling to your liking. To do this, run php artisan vendor:publish and export the livewire-calendar tag.

  • calendar-view which can be any blade.php view that renders the whole component. It's advised to override this view with an altered copy of the base calendar-view eg adding a view next to the component.

  • day-view which can be any blade.php view that will be used to render each day of the month. This view will be injected with the following properties: componentId (id of the Livewire component) , day (day of the month as a Carbon instance) , dayInMonth (if the day is part of the month or not) , isToday (if the day is today's date) , events (events collection that correspond to this day)

Example

<livewire:appointments-grid
    calendar-view="path/to/view/starting/from/views/folder"
    day-view="path/to/view/starting/from/views/folder"
/>

Interaction customization

You can override the following methods to add interactivity to your component

public function onDayClick($year, $month, $day)
{
    // This event is triggered when a day is clicked
    // You will be given the $year, $month and $day for that day
}

public function onEventClick($eventId)
{
    // This event is triggered when an event card is clicked
    // You will be given the event id that was clicked 
}

public function onEventDropped($eventId, $year, $month, $day)
{
    // This event will fire when an event is dragged and dropped into another calendar day
    // You will get the event id, year, month and day where it was dragged to
}

Automatic polling

You can also add automatic polling if needed using pollMillis parameters. You can combo with pollAction in order to call a specific action in your component at the desired polling interval.

Disabling interactions

By default click and drag/drop events are enabled. To disable them you can use the following parameters when rendering the component

<livewire:appointments-grid
    :day-click-enabled="false"
    :event-click-enabled="false"
    :drag-and-drop-enabled="false"
/>

Testing

composer test

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

Comments
  • LARAVEL 8 ISSUE

    LARAVEL 8 ISSUE

    Return value of App\Http\Livewire\AppointmentsCalendar::events() must be an instance of Illuminate\Database\Eloquent\Collection, instance of Illuminate\Support\Collection returned (View: /Applications/MAMP/htdocs/todo/resources/views/vendor/jetstream/components/welcome.blade.php) (View: /Applications/MAMP/htdocs/todo/resources/views/vendor/jetstream/components/welcome.blade.php)

    opened by salmanrajz 6
  • Installation error

    Installation error

    I get this error when I try to install the package

    Problem 1 - Root composer.json requires asantibanez/livewire-calendar ^2.1 -> satisfiable by asantibanez/livewire-calendar[2.1.0]. - asantibanez/livewire-calendar 2.1.0 requires illuminate/support ^6.0|^7.0|^8.0 -> found illuminate/support[v6.0.0, ..., 6.x-dev, v7.0.0, ..., 7.x-dev, v8.0.0, ..., 8.x-dev] but it conflicts with your root composer.json require (^9.28).

    You can also try re-running composer require with an explicit version constraint, e.g. "composer require asantibanez/livewire-calendar:*" to figure out if any version is installable, or "composer require asantibanez/livewire-calendar:^2.1" if you know which you need.

    Installation failed, reverting ./composer.json and ./composer.lock to their original content.

    I have laravel version 9.19 and illuminate/support 9.28. thank you in advance for your return.

    opened by roomdada 5
  • Pulling in LivewireCalendar breaks Jetstream Livewire components

    Pulling in LivewireCalendar breaks Jetstream Livewire components

    Hi there,

    This is a hobby for me and infact, the first issue i've ever submitted on any public repo before, although i have tested this back and forth a few times.

    System Versions (all at time of writing) OS: MacOS using Valet Laravel: Latest Livewire: Latest

    Replication

    • Brand new laravel app with --jet flag using latest laravel installer
    • No additional features added to jetstream in test app
    • Compile assets and migrate database
    • Load the "Profile" page from the dropdown to prove it works
    • Pull in livewire calendar as require from composer following readme
    • Try to reload the profile page

    Thoughts The error displayed in my app was different, it couldn't locate the declared Livewire Components from the jetstream package, although an error is still thrown with a fresh install Although i'm not confident enough to make a Pull Request here, i have dismantled the package and made it local (out of the vendor DIR and with no ServiceProvider etc. and it all plays nicely.

    Screenshot jet-livewire-test livewire calendar breaking jetstream

    Hope this is of some help to you!

    opened by mitch1793 3
  • getting `Unable to find component: [profile.update-profile-information-form]`

    getting `Unable to find component: [profile.update-profile-information-form]`

    Hi, as soon as I install your package i get this error, any idea what might be wrong?

    it's in vendor/livewire/livewire/src/LivewireManager.php:53

    if I remove your package it's fixed immediately, so I suppose it's doing something wrong

    opened by sathio 2
  • Add directive in boot()

    Add directive in boot()

    Similar to https://github.com/asantibanez/livewire-resource-time-grid/pull/4 The Blade direct should be in the boot() method, to guarantee correct order of dependencies. Otherwise this will result in an error with the default Jetstream install:

    Livewire\Exceptions\ComponentNotFoundException Unable to find component: [navigation-dropdown]

    opened by barryvdh 2
  • Request: poll for calendar changes

    Request: poll for calendar changes

    Could we optionally, or by default, add Livewire polling to the calendar?

    Adding wire:poll here: https://github.com/asantibanez/livewire-calendar/blob/master/resources/views/calendar.blade.php#L1

    Seems to the job.

    The use case I want to enable is creating events on the same screen as the calendar and have them appear dynamically, see the following video:

    https://www.loom.com/share/cffde78ef31a481faef94f77ef63c939

    opened by aaronmyatt 2
  • Click event for edit an unschedules event does not work but works inside the calendar...

    Click event for edit an unschedules event does not work but works inside the calendar...

    I added in unschedules events the edit button there but it does not work but in the calendar the same code works!

    here the code

                        <button
                            wire:click.stop="editEvent({{ $event->id }})"
                            type="button"
                            class="mt-2 inline-flex items-center px-2 py-1 border border-transparent text-xs leading-4 font-medium rounded text-indigo-700 bg-indigo-100 hover:bg-indigo-50 focus:outline-none focus:border-indigo-300 focus:shadow-outline-indigo active:bg-indigo-200 transition ease-in-out duration-150">
                            {{ __('messages.edit') }} 
                        </button>
                        <button
                            wire:click.stop="deleteEvent({{ $event->id }})"
                            type="button"
                            class="mt-2 inline-flex items-center px-2 py-1 border border-transparent text-xs leading-4 font-medium rounded text-indigo-700 bg-indigo-100 hover:bg-indigo-50 focus:outline-none focus:border-indigo-300 focus:shadow-outline-indigo active:bg-indigo-200 transition ease-in-out duration-150">
                            {{ __('messages.delete') }} 
                        </button>
    

    the editEvent function

        public function editEvent($eventId)
        {
            $this->selectedAppointment = PharmacyAppointments::find($eventId);
        }
    

    Error

    Call to a member function format() on null
    

    Any ideas why it does not work in unschedules events but when moved into the calendar it works? thanks

    opened by rapgithub 1
  • Some difficulty in making it work

    Some difficulty in making it work

    Hi, I have installed the package and made it work but I have some problems. For example: drag and drop doesn't work. To test the package I installed laravel, liveware, tailwind css and then the calendar from scratch. The display is correct but drag and drop does not work and neither do the onDayClick, onEventClick and onEventDropped functions. I try to explain myself better: I move the appointment to another day, the square of the day lights up (it signals it to me) but releasing it does not move it, it returns to its original place. Of course I added @livewireScripts and @livewireCalendarScripts. Then the documentation is not clear. For example, I can't get the 3 methods goToPreviousMonth, goToNextMonth and goToCurrentMonth to go. Also the doc talks about a livewire component: appointments-grid that doesn't seem to exist. Another thing: is it possible to put appointments with several days in the calendar? Thanks

    opened by myfender 1
  • getting ErrorException `Undefined variable: pollMillis`

    getting ErrorException `Undefined variable: pollMillis`

    Hi, I've followed the Readme file but it looks like I can't use the component. I'm on Laravel 8.13

    as far as I understand this should be enough:

    <?php
    
    namespace App\Http\Livewire;
    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 with Pamela',
                    'description' => 'Work stuff',
                    'date' => Carbon::tomorrow(),
                ],
            ]);
    
        }
    }
    

    I'm then calling <livewire:appointments-calendar />

    on my view, but I receive this error

    ErrorException
    Undefined variable: pollMillis (View: [...]/vendor/asantibanez/livewire-calendar/resources/views/calendar.blade.php)
    

    any idea what might be wrong?

    opened by sathio 1
  • Feature request: isPast()

    Feature request: isPast()

    Would be nice to alter the display of a day providing it's in the current month, but in the past.

    Have published vendor files for now and added

                                            'isToday' => $day->isToday(),
                                            'isPast' => $day->isPast(),
                                            'events' => $getEventsForDay($day, $events),
    

    But this really is a nice bit of work! Thanks for sharing it!

    opened by wrabit 1
  • Make event title dynamic

    Make event title dynamic

    I have just made the word event on Calendar dynamic. To overwrite it in your system, you have just to create a public variable called $eventTitle.

    eg: public $eventTitle = 'Rota';

    or public $eventTitle;

    public function mount() { $eventTitle = 'rota'; }

    NOTE: Feel free to close it.

    Thank you

    opened by cntabana 0
  • Class

    Class "Asantibanez\LivewireCalendar\LivewireCalendar" not found

    Im getting an Class "Asantibanez\LivewireCalendar\LivewireCalendar" not found from vscode when running the application, but my ide does recognize the class. Dont know how to fix it. It is a fresh laravel 9 application and to use this package i used the workaround https://github.com/asantibanez/livewire-calendar/issues/32#issuecomment-1150032111 mentioned here.

    image

    opened by Deniz073 1
  • Any way we can pass events or model to the component ?

    Any way we can pass events or model to the component ?

    I am using it in a list view of users to view calendar for each users , i am thinking if we can pass events or model to the component rather than loading in the component.

    opened by skakrecha 5
  • Could not install it on Laravel 9

    Could not install it on Laravel 9

    Your requirements could not be resolved to an installable set of packages.

    Problem 1 - Root composer.json requires asantibanez/livewire-calendar ^2.1 -> satisfiable by asantibanez/livewire-calendar[2.1.0]. - asantibanez/livewire-calendar 2.1.0 requires illuminate/support ^6.0|^7.0|^8.0 -> found illuminate/support[v6.0.0, ..., 6.x-dev, v7.0.0, ..., 7.x-dev, v8.0.0, ..., 8.x-dev] but these were not loaded, likely because it conflicts with another require.

    opened by gldtn 26
Releases(2.1.0)
  • 2.1.0(Jan 25, 2021)

  • 2.0.0(Oct 14, 2020)

    • Added support for Laravel 8
    • Added support for Livewire v2
    • Added on/off flag for Day click event
    • Added on/off flag for Event click event
    • Added on/off flag for Drag and Drop event
    • Added ability to automatically poll component with pollMillis and pollAction parameters
    • Added tests
    Source code(tar.gz)
    Source code(zip)
  • 1.0.0(May 30, 2020)

Owner
Andrés Santibáñez
Andrés Santibáñez
Laravel: Data to Monthly Converter

Laravel: Data to Monthly Converter Using this package you will be able to converts your collection using a timestamp field to order data monthly or ye

101INFOTECH 9 Nov 23, 2022
Laravel-comments-livewire - Livewire components for the laravel-comments package

Associate comments and reactions with Eloquent models This package contains Livewire components to be used with the spatie/laravel-comments package. S

Spatie 15 Jan 18, 2022
Laravel Livewire full page component routing.

Laravel Livewire Routes Laravel Livewire full page component routing. This package allows you to specify routes directly inside your full page Livewir

null 22 Oct 6, 2022
Laravel Livewire form component with declarative Bootstrap 5 fields and buttons.

Laravel Livewire Forms Laravel Livewire form component with declarative Bootstrap 5 fields and buttons. Requirements Bootstrap 5 Installation composer

null 49 Oct 29, 2022
Livewire component that brings Spotlight/Alfred-like functionality to your Laravel application.

About LivewireUI Spotlight LivewireUI Spotlight is a Livewire component that provides Spotlight/Alfred-like functionality to your Laravel application.

Livewire UI 792 Jan 3, 2023
A TALL-based Laravel Livewire component to replace the (multiple) select HTML input form with beautiful cards.

TALL multiselect cards A TALL-based Laravel Livewire component to replace the (multiple) select HTML input form with beautiful cards. Table of content

Frederic Habich 19 Dec 14, 2022
Livewire component that brings Spotlight/Alfred-like functionality to your Laravel application.

About Wire Elements Spotlight Wire Elements Spotlight is a Livewire component that provides Spotlight/Alfred-like functionality to your Laravel applic

Wire Elements 790 Dec 27, 2022
A dynamic table component for Laravel Livewire - For Slack access, visit:

A dynamic Laravel Livewire component for data tables. Bootstrap 4 Demo | Bootstrap 5 Demo | Tailwind Demo | Demo Repository Installation You can insta

Anthony Rappa 1.3k Jan 1, 2023
A dynamic Laravel Livewire component for multi steps form

Livewire component that provides you with a wizard that supports multiple steps form while maintaining state.

Vildan Bina 233 Jan 4, 2023
An advanced datatable component for Laravel Livewire.

Livewire Smart Table An advanced, dynamic datatable component with pagination, sorting, and searching including json data. Installation You can instal

Turan Karatuğ 87 Oct 13, 2022
Livewire component that provides you with a modal that supports multiple child modals while maintaining state.

About LivewireUI Modal LivewireUI Modal is a Livewire component that provides you with a modal that supports multiple child modals while maintaining s

Livewire UI 806 Jan 6, 2023
Livewire component that provides you with a modal that supports multiple child modals while maintaining state.

About Wire Elements Modal Wire Elements Modal is a Livewire component that provides you with a modal that supports multiple child modals while maintai

Wire Elements 806 Jan 6, 2023
Livewire component for dependant and/or searchable select inputs

Livewire Select Livewire component for dependant and/or searchable select inputs Preview Installation You can install the package via composer: compos

Andrés Santibáñez 441 Dec 19, 2022
Render a Livewire component on a specific target in the DOM.

Livewire Portals Render a Livewire component on a specific target in the DOM. Install THIS PACKAGE IS STILL IN DEVELOPMENT, TO USE, PLEASE ADD THE FOL

Jeff Ochoa 20 Aug 11, 2022
This package allows you to render livewire components like a blade component, giving it attributes, slots etc

X-livewire This package allows you to render livewire components like a blade component, giving it attributes, slots etc. Assuming you wanted to creat

null 7 Nov 15, 2022
A minimalistic event calendar Tool for Laravel's Nova 4

Event calendar for Laravel Nova 4 An event calendar that displays Nova resources or other time-related data in your Nova 4 project on a monthly calend

wdelfuego 44 Jan 1, 2023
A simple PHP package to show SweetAlerts with the Laravel Framework

Easy Sweet Alert Messages for Laravel Installation Require the package using Composer. composer require uxweb/sweet-alert If using laravel < 5.5 inclu

Uziel Bueno 824 Jan 7, 2023
The Most Popular JavaScript Calendar as a Filament Widget 💛

The Most Popular JavaScript Calendar as a Filament Widget ?? Features Accepts all configurations from FullCalendar Event click and drop events Upcomin

Guilherme Saade 62 Dec 31, 2022
The Rickies, the prediction draft show of the Connected podcast

The Rickies Predictions with risk, flexing, and passion. On Connected at Relay FM. The Rickies are a prediction draft show on the Connected podcast at

Lex Postma 21 Oct 1, 2022