Hmmmm ... why do you need AlpineJS to display a reservation ID ?
<div>
<p>{{ $reservationID }}</p>
</div>
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I'm currently working on a project using Livewire and Alpine.js and have run into an issue. I have a reservationID property in my Livewire component that I'm trying to sync with Alpine.js using the @entangle directive.
Here's what my Alpine.js code looks like:
<div x-data="{ reservationID: $persist(@entangle('reservationID')) }" x-init="$nextTick(() => { console.log(reservationID); })">
<p x-text="reservationID"></p>
</div>
However, even though the in Alpine.js correctly displays the reservation ID, the $reservationID in my Livewire component is always null. I'm not sure why this is happening.
Here's the relevant part of my Livewire component:
public Reservation $reservation;
public ?int $reservationID = null;
public function checkReservation(): void
{
if (!$this->reservationID) {
$this->reservation = Reservation::create(['location_id' => 1,]);
$this->reservationID = $this->reservation->id;
} else {
$this->reservation = Reservation::find($this->reservationID);
}
}
I'm trying to persist the reservationID across page loads, but it seems to be lost. Could anyone provide any insight on what I might be doing wrong or any steps I can take to troubleshoot this issue?
Thanks in advance for your help!
Please or to participate in this conversation.