To start, when you have an element like this on your initial page load:
<input value="whatever" disabled />
If you try to inject wire:model="$var"
on that input, it won’t do anything because livewire isn’t tracking it, so that wire:model should be put in via a conditional if it’s not disabled. It’s still possible to change the $var on a different element though. (It will revert back to the original $var you modeled it to after the round trip, but the change will still happen first.) Plus to me it’s a smell to have a wire:model on a disabled input anyway.
Edit To Add: It’s been a while since I tested this and I doubt that it has changed, but it’s possible this is outdated and you should test it for yourself.
Let’s go down the million ways to skin a cat road, and start out in the component.
Hard code the attributes being updated in a separate method, conditional the method to call in your wire:click or form:submit, however you’re calling them. Then even if another property gets changed, it’s never being assigned to the model.
You could also have your component set up with only properties available, extend it with another component class and add the properties available for creation, do a polymorphic call for which of those two components should be called. Would be possible to have them both use the same view.
Go the crazy route of extreme obfuscation and name your modelable properties some randomness.
Create a immutable concept for your models. Something like (psudo code):
protected array $immutable = ['always', 'immutable'];
public function makeImmutable(string $attribute)
{
$this->immutable[] = $attribute;
}
public function __set($key, $value)
{
throw_if(array_key_exists($key, $this->immutable), AttributeImmutableException::class);
parent::__set($key, $value);
}
Something like that would give you some defaults and the ability to call $model->makeImmutable('another')
as needed. I’m sure I’m not the first person to come up with something like that and there’s probably a more feature rich package out there somewhere.
Just keep experimenting until you find something comfortable.