Best practice for multiple dynamic properties
Looking for advice for the following scenario:
My form also has several places where I will be using the
Product
data. Do I really need to execute the Product::find($productId)
on every dynamic
property?
Example:
After the TextInput::make('quantity')
is ->live(onBlur: true)
I have another field that will show the Total
which is quantity * $product->price
. Calling Product::find...
for the 3rd time seems a bit much.
is there a more efficient approach that I might be not considering, cause calling the Product
model every time doesn't seem efficient.
Thanks in advance for the advice2 Replies
A resource is just a PHP class !
You can define an array variable
And set it's value to your model each time the user changes the selected product with AfterstateUpdated