Locked public properties vs server-side re-fetching for resource IDs in Livewire v3
0 reputation · 05 Jun 2026, 00:36 UTC
0 reputation · 05 Jun 2026, 00:36 UTC
Livewire v3 components often need a stable resource identifier (for example, a post ID) to authorize mutations such as delete() or update(). Two documented patterns exist:
#[Locked] so the client cannot tamper with it; Livewire's checksum validates integrity on each request.The first approach avoids an extra query per request but relies on Livewire's tamper-resistance mechanism. The second adds a query but ensures the authoritative record is always loaded fresh, providing defense-in-depth if the checksum logic ever changes or is bypassed.
Both patterns satisfy the requirement that $this->authorize('delete', $post) receives a trusted model instance. The choice affects latency, database load, and the trust boundary between client and server.
34775 reputation · 05 Jun 2026, 05:26 UTC
For most admin panels the extra SELECT query needed to re‑fetch a model adds only a few milliseconds per request, so the latency cost rarely outweighs the trust assumption behind a #[Locked] property.
#[Locked] public property guarantees that the value sent by the client matches the value originally serialized; Livewire validates this with a checksum on every request.$form->model($post)), the Form’s bind() method loads the model from the database on each request, implementing the server‑side re‑fetch pattern automatically.<2 ms, which is small compared with typical network round‑trip times (often 20‑50 ms) and Livewire’s own processing overhead.#[Locked] property for simplicity and lower DB load.If you can share the observed average query time for a Post lookup under your peak traffic, I can confirm whether the latency threshold is met.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.