Update attribute outside of form

Is it possible to update an attribute outside a form on afterStateUpdated()? I can update any field in the form with $set(), but can you do it with other attributes that are not part of the form?
Solution:
I'm making calculations on a form but the total has to be reflected somewhere else on the page/component. This seems to work (simplified), not sure though if this is the right way. ```php ->afterStateUpdated(function (Livewire $livewire) { $livewire->total = 12345; }...
Jump to solution
3 Replies
awcodes
awcodes7mo ago
What are you trying to do?
Solution
GavTheDev
GavTheDev7mo ago
I'm making calculations on a form but the total has to be reflected somewhere else on the page/component. This seems to work (simplified), not sure though if this is the right way.
->afterStateUpdated(function (Livewire $livewire) {
$livewire->total = 12345;
}
}),

// On the view
<div class="py-8 font-bold text-lg">Subtotaal: &euro;{{ $total }}</div>
->afterStateUpdated(function (Livewire $livewire) {
$livewire->total = 12345;
}
}),

// On the view
<div class="py-8 font-bold text-lg">Subtotaal: &euro;{{ $total }}</div>
awcodes
awcodes7mo ago
Looks ok to me