// DOKUMENTACE CALENDAR 3.x

Custom label content

By default, resource labels render with the default view of the calendar package. Just like with event content, you can provide your own.

The same rule applies here: the content is rendered once on the server and reused for every resource, so you cannot access the resource data from blade or PHP. Each label is wrapped in an alpine component that exposes the resource data, and you build the dynamic parts with AlpineJS.

A single content for all resources

If all your resources render the same way, return a view or a HtmlString from the resourceLabelContent method (or its alias defaultResourceLabelContent):

use Illuminate\Support\HtmlString;

protected function resourceLabelContent(): HtmlString | string
{
    return view('calendar.resource');
}

The blade view uses alpine to read the resource data:

<div class="flex flex-col items-start">
    <span x-text="resource.title"></span>
</div>

Anything you passed via extendedProps is available under resource.extendedProps.

A content per model

If you display multiple models as resources, you can implement a label content method per model. You have two options:

  • Define a method with any name and add the #[CalendarResourceLabelContent] attribute,
  • or follow the naming convention camelCaseModelNameResourceLabelContent, such as fooResourceLabelContent
use Guava\Calendar\Attributes\CalendarResourceLabelContent;
use Illuminate\Support\HtmlString;

// Variant 1
#[CalendarResourceLabelContent(Foo::class)]
protected function myFooLabel(): HtmlString | string
{
    return view('calendar.foo-resource');
}

// Variant 2
protected function barResourceLabelContent(): HtmlString | string
{
    return view('calendar.bar-resource');
}

Both variants are equal, it's up to your personal preference which one you want to use.

guava/calendar 417K instalací · 310 hvězd
// COOKIES

Pár cookies drží web v chodu; další si pamatují nastavení nebo počítají návštěvy. Vy rozhodujete, co poběží.

Zásady cookies