FilamentF
Filament14mo ago
Dima

How to make filament to trim form input?

Laravel uses TrimStrings middleware to automatically trim all form string inputs. However, I noticed that filament allows data to be saved with trailing spaces. How do I enable filament to trim form inputs?
Solution
// its by design from Livewire to skip TrimStrings
// in the source code here
  vendor/livewire/livewire/src/Mechanisms/HandleRequests/HandleRequests.php
// in the boot method they have
$this->skipRequestPayloadTamperingMiddleware();

// which does exactly this
    function skipRequestPayloadTamperingMiddleware()
    {
        .....        
        // as you can see it skip it
        \Illuminate\Foundation\Http\Middleware\TrimStrings::skipWhen(function () {
            return $this->isLivewireRequest();
        });
    }
Was this page helpful?