I recently found https://github.com/livewire/livewire/issues/1950 and https://github.com/livewire/livewire/issues/823 that state:
Not trimming strings and converting to null is the desired behavior of Livewire.
You can add traits to bypass this and that’s what I would recommend if you want to re-introduce this behavior.
So my question is, how would you create a trait that would auto trim and convert empty string to null for a model property?
I can do this before validation ($this->status is a laravel model), but will it break something down the road I can’t think of?:
foreach ($this->status->getAttributes() as $key => $value){
$value = is_string($value) ? trim($value) : $value;
$this->status->{$key} = is_string($value) && $value === '' ? null : $value;
}
It would be nice to do this at the request before its stuck into $this->status.