saade / filament-fullcalendar

The Most Popular JavaScript Calendar as a Filament Widget
MIT License
282 stars 85 forks source link

Typed property Saade\FilamentFullCalendar\Widgets\FullCalendarWidget::$record must not be accessed before initialization #131

Open darren-glanville opened 11 months ago

darren-glanville commented 11 months ago

I have a filament action within headerActions method for the calendar.

It is using a modal form which I want to run to filter the events, the error appears when trying to submit that form. Any ideas on how to fix this would be much appreciated.

return [ Action::make('filter') ->label(__('ev-bookings.actions.filter-locations')) ->icon('heroicon-s-funnel') ->modalWidth('sm') ->modalIcon('heroicon-o-funnel') ->modalCancelAction(false) ->modalSubmitActionLabel(__('ev-bookings.actions.filter-locations')) ->modalFooterActionsAlignment('center') ->form([ CheckboxListColor::make('color') ->label(__('ev-bookings.fields.locations')) ->hiddenLabel(true) ->options($locations) ->required() ->columns(2) ]) ->action(function (array $data): void { // will do something }) ];

Hegabovic commented 9 months ago

i'm having the same error when creating Events with additional data

this line gives this error : 'calendar_id' => $this->record->id

FinnPaes commented 5 months ago

I had the same issue. It's because you didn't define the model in the calendar widget like this:

public Model | string | null $model = Appointment::class; In my case my model is Appointment, so of course change that to the model which contains your events/dates. Full example:

<?php

namespace App\Filament\Widgets;

use App\Models\Appointment;
use Illuminate\Database\Eloquent\Model;
use Saade\FilamentFullCalendar\Data\EventData;
use Saade\FilamentFullCalendar\Widgets\FullCalendarWidget;

class CalendarWidget extends FullCalendarWidget
{
    public Model | string | null $model = Appointment::class;

    public function fetchEvents(array $fetchInfo): array
    {
        return Appointment::query()
            ->where('start', '>=', $fetchInfo['start'])
            ->where('end', '<=', $fetchInfo['end'])
            ->get()
            ->map(
                fn (Appointment $appointment) => EventData::make()
                    ->id($appointment->id)
                    ->title($appointment->title)
                    ->start($appointment->start->toDateTimeLocalString())
                    ->end($appointment->end->toDateTimeLocalString())
            )
            ->toArray();
    }
}