GuavaCZ / calendar

MIT License
140 stars 13 forks source link

[Help]: Resources #11

Closed aeq-dev closed 2 months ago

aeq-dev commented 4 months ago

What feature would you like to add?

I'm trying to setup resources, but cannot display events on each resource (Events created but not displayed under their resources). Here's my setup : Models : Activity has many Task Task Model :

 public function toEvent(): Event|array
    {
        return Event::make($this)
            ->title($this->title)
            ->start($this->starts_at)
            ->end($this->ends_at)
            ->backgroundColor($this->bg_color ?? 400)
            ->textColor($this->text_color ?? '#ffffff')
            ->extendedProps(['users' => $this->workers])
            ->resourceIds([$this->activity_id]);
    }

Activity Model :

public function toResource(): array | Resource
    {
        return Resource::make($this)
            ->title($this->name);
    }

CalendarWidget :

public function getOptions(): array
    {
        return [
            'headerToolbar' => [
                'start' => 'title',
                'center' => 'resourceTimeGridDay,dayGridMonth,timeGridWeek,timeGridDay',
                'end' => 'today prev,next',               
            ]
        ];
    }

aaa today

Notes

No response

lukas-frey commented 4 months ago

in your Activity model in the toResource method, you need to define an ID for the resource, not pass $this to the Resource Value Object.

public function toResource(): array | Resource
    {
        return Resource::make($this->id)
            ->title($this->name);
    }

But thanks for the notice, I'll add to the next release that it will automatically use the primary key if the whole model is passed, to keep it same with the Eventable API.

lukas-frey commented 4 months ago

In version 1.2.1, passing just $this to the Resource should work now and it will use the primary key as the ID for the resource.

aeq-dev commented 4 months ago

Thank you so much :))) It works now

aeq-dev commented 2 months ago

Hi @lukas-frey Let's say we have an event model Task which belongs to User & Activity, How could we create two resources view one per User & other per Activity ? Thanks

aeq-dev commented 2 months ago

Never mind, just use resourceIds :)))) Sorry :))))