Certainly! In Filament, form fields like TextInput have their own built-in methods for setting validation rules (e.g., required(), maxLength()). However, if you want to inject raw Laravel validation rules (which can be handy for reusing DTO validation logic), you can use the rules() method directly:
TextInput::make('title')->rules(['required', 'max:32'])
This will work as intended and Laravel will apply these validation rules server-side when the form is submitted. However, do note:
- When you use
rules(), Filament won't automatically handle things like max length on the frontend. For example, the input field itself will not have amaxlength="32"attribute unless you also usemaxLength(32). - Using DTO (Data Transfer Object) validation from Spatie is fine if you want to keep validation logic centralized, but you may lose some of the automatic client-side helpers that Filament provides.
TL;DR:
You can use rules() like:
TextInput::make('title')->rules(['required', 'max:32'])
But for best UX (client-side validation, attributes, etc.), combine it with Filament’s methods:
TextInput::make('title')
->maxLength(32) // applies frontend attribute
->required() // shows required asterisk
->rules(['required', 'max:32']); // shares rules with DTO or request validation
This approach gives you the best of both worlds: DTO/server-side validation with Spatie AND Filament’s frontend polish.