Strict Mode für Form Requests im Laravel-Framework
Mit FormRequest::failOnUnknownFields() schlägt die Validierung fehl, wenn eingehende Felder nicht in rules() deklariert sind, und einzelne Requests können sich per Eigenschaft $failOnUnknownFields = false ausnehmen.
Pull request by @NurullahDemirel
Strict mode lands in form requests, mirroring the spirit of Model::shouldBeStrict(). Flip it on in your AppServiceProvider and any incoming field that isn't declared in rules() will fail validation instead of silently slipping through:
use Illuminate\Foundation\Http\FormRequest;
public function boot(): void
{
FormRequest::failOnUnknownFields(! app()->isProduction());
}
Need to opt a single request out (say, a public webhook with unpredictable payloads)? Set the property on the class:
class PublicWebhookRequest extends FormRequest
{
protected ?bool $failOnUnknownFields = false;
public function rules(): array { /* ... */ }
}
It's fully backward compatible, off by default, and a great safety net during development. Learn more in the validation documentation.