Summer Sale! All accounts are 50% off this week.

Ronan-Lenor's avatar

Ronan-Lenor wrote a reply+100 XP

2w ago

Livewire, Security, and UUIDs (oh my!)

i wanted to also use the internal/external keys system with the HasUlids trait. i ended to add this workaround in my model class:

public function getKey()
{
    foreach (debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS) as $aBacktrace)
    {
        if (($aBacktrace['class'] ?? null) == \Livewire\LivewireManager::class)
        {
            // Public Key
            return $this->getRouteKeyName();
        }
    }

    // Primary Key
    return parent::getKey();
}

This force Livewire to build the snapshot (hardcoded in the HTML DOM) with the ULID instead of the Primary key (eg: wire:snapshot="..."key":"...ulid..."). So that the subrequests also transmit the ulid instead of the raw id.

not sure it will cover every cases... 🤷‍♂️