How about
<div x-data="{status: '{{$status}}'">
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I wish to update the button text upon click. However, for the initial load, the button status is determined by the value I have in database. Let me explain -
Blade -
<button>{{$status->active ? 'Deactivate' : 'Activate'}}</button>
Now, I'm aware that I can control this with AlpineJS as -
<div x-data="statusController">
<button x-text="status" @click="updateStatus()"></button>
</div>
<script>
function statusController() {
return {
status = 'Activate',
updateStatus() {
this.status = "Deactivate"
}
}
}
But this approach does not allow me to set the button status when the page is loaded for the first time (i.e. status determined by the value from database).
Can someone guide? Thanks!
How about
<div x-data="{status: '{{$status}}'">
Please or to participate in this conversation.