How to pass custom data to view from Custom Field?

I have a custom field called Checklist.

In a loop, I am passing the $record to a custom method called device, and a checklist_id from a pivot table 'checklist_device' to a method called list.

Checklist::make('items')
    ->device($record)
    ->list($list->pivot->checklist_id)


This is to render specific json items from this pivot table in a field called 'items'.

This is my custom field class:
class Checklist extends Field
{
    protected string $view = 'forms.components.checklist';

    protected int $list;
    protected Model $device;

    protected function setUp(): void
    {
        parent::setUp();
    }

    public function list(int $list): static
    {
        $this->list = $list;

        return $this;
    }

    public function getList(): int
    {
        return $this->list;
    }

    public function device($device)
    {
        $this->device = $device;

        return $this;
    }

    public function getDevice()
    {
        return $this->device;
    }



    public function render(): View
    {
        $checklistItems = $this->getDevice()
            ->checklists()
            ->where('checklist_id', $this->getList())
            ->first()
            ->pivot
            ->items;

        return view(
            $this->getView(),
            array_merge(
                ['attributes' => new ComponentAttributeBag()],
                $this->extractPublicProperties(),
                $this->extractPublicMethods(),
                isset($this->viewIdentifier) ? [$this->viewIdentifier => $this] : [],
                $checklistItems
            ),
        );
    }
}


I guess what I'm failing to understand is how to bypass that 'make' function and in my view, have custom data from the render method instead, as you can see $checklistItems is currently not doing anything.
Was this page helpful?