TrimStrings Middleware is not working?

I add the TrimStrings middleware in the middleware method in the config of the panel, but it does not seem to work. I save a form where I put spaces around a field and these spaces are saved in the database. Anyone has experienced that? Am I doing something wrong?
2 Replies
Tieme
Tieme9mo ago
did you persist the middleware? https://filamentphp.com/docs/3.x/panels/configuration#applying-middleware
->middleware([
// ...
], isPersistent: true);
->middleware([
// ...
], isPersistent: true);
jawaad
jawaad5w ago
It still does not work..
use Illuminate\Foundation\Http\Middleware\TrimStrings;

// ...
->middleware([
TrimStrings::class,
], isPersistent: true)
use Illuminate\Foundation\Http\Middleware\TrimStrings;

// ...
->middleware([
TrimStrings::class,
], isPersistent: true)
The only working solution is using configure in appService in boot:
Forms\Components\TextInput::configureUsing(function (Forms\Components\TextInput $textInput): void {
$textInput
->dehydrateStateUsing(function (?string $state): ?string {
return is_string($state) ? trim($state) : $state;
});
});
Forms\Components\TextInput::configureUsing(function (Forms\Components\TextInput $textInput): void {
$textInput
->dehydrateStateUsing(function (?string $state): ?string {
return is_string($state) ? trim($state) : $state;
});
});
Not as perfect as I espected but, I think TextInput is enough for me, and if we want, we can also add in Textarea, Richeditor as well..
Want results from more Discord servers?
Add your server