Skip to content

fix: trim whitespace from string attributes on BaseModel#2504

Open
bpotmalnik wants to merge 1 commit into
lunarphp:1.xfrom
bpotmalnik:fix/trim-string-attributes-on-base-model
Open

fix: trim whitespace from string attributes on BaseModel#2504
bpotmalnik wants to merge 1 commit into
lunarphp:1.xfrom
bpotmalnik:fix/trim-string-attributes-on-base-model

Conversation

@bpotmalnik
Copy link
Copy Markdown
Contributor

Laravel's TrimStrings middleware is intentionally skipped for Livewire requests (Livewire\Mechanisms\HandleRequests\HandleRequests calls TrimStrings::skipWhen). This means leading/trailing whitespace entered via Livewire forms (e.g. the admin panel) is never stripped before reaching the model, allowing values like " size " to be persisted.

Override setAttribute() on BaseModel to trim all incoming string values before delegating to the parent. This covers every model in Lunar (handle, sku, slug, coupon, code, reference, postcode, etc.)

Fixes #1664

@github-project-automation github-project-automation Bot moved this to Todo in Roadmap May 29, 2026
@bpotmalnik bpotmalnik force-pushed the fix/trim-string-attributes-on-base-model branch from 540ef03 to bd156ce Compare May 29, 2026 11:31
@bpotmalnik
Copy link
Copy Markdown
Contributor Author

I was considering if it is breaking change or not, but it would break things only if people would assert things agains hardcoded strings (which likelihood is pretty low) so I think it can got to v1.

Laravel's TrimStrings middleware is intentionally skipped for Livewire
requests (Livewire\Mechanisms\HandleRequests\HandleRequests calls
TrimStrings::skipWhen). This means leading/trailing whitespace entered
via Livewire forms (e.g. the admin panel) is never stripped before
reaching the model, allowing values like "  size  " to be persisted.

Override setAttribute() on BaseModel to trim all incoming string values
before delegating to the parent. This covers every model in Lunar
(handle, sku, slug, coupon, code, reference, postcode, etc.)

Fixes lunarphp#1664
@bpotmalnik bpotmalnik force-pushed the fix/trim-string-attributes-on-base-model branch from bd156ce to 84e543d Compare May 29, 2026 11:39
@wychoong
Copy link
Copy Markdown
Contributor

I don’t think this is a suitable fix

  • it’s too heavy handed (a Model::update([…]) will be affected too)
  • Not the common livewire/filament form expectation
  • Probably more suitable to implement Input::configureUsing( ->dehydrateStateUsing ) in your app to trim the fields

@bpotmalnik
Copy link
Copy Markdown
Contributor Author

bpotmalnik commented May 29, 2026

@wychoong I hear you. I still think that reinstating default Laravel behavior would be handy for users (developers) using the package.

As it is not indeed default filament behavior, but this package is kind of special case where lunar is in control of both core and admin panel itself (filament) which can drive handy behaviors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

Input values aren't being trimmed or validated when saved on resource

2 participants