- What is nette/schema and how does it work in Laravel?
- Nette Schema is a lightweight, framework-agnostic PHP library for validating and normalizing structured data. You define schemas as code with Expect, Structure, and Processor, then process arrays or objects to coerce values, apply defaults, and collect clear error messages. In Laravel it works best as a boundary layer for config loading, API payloads, webhook bodies, and DTO hydration. It does not ship a Laravel service provider, Rule bridge, or container bindings, so all integration glue is yours to own.
- Does nette/schema work with Laravel 10, 11, and 12?
- Yes. nette/schema requires PHP 8.1 or later, which aligns with Laravel 10, 11, and 12, and it has no conflicts with Laravel's dependency tree. Install the supported line with composer require nette/schema:^1.3. Legacy applications on PHP 8.0 or Laravel 9 and earlier are blocked by the PHP requirement.
- How do I install nette/schema in a Laravel project?
- Run composer require nette/schema:^1.3. There is no service provider to register and no configuration file to publish. Use Expect and Processor directly in your own adapter, service class, or container binding. Before adopting it commercially, confirm that your legal team has cleared the repository's license file.
- Should I use nette/schema instead of Laravel's Validator or FormRequest?
- No, it is not a replacement for Laravel's Validator or FormRequest. Laravel's validator is request-scoped, rules-array-driven, and integrates with MessageBag and 422 responses, while nette/schema is immutable, composable schema-as-code that can be reused across config loading, DTO hydration, and CLI commands. If you use both without an explicit boundary policy, you will end up with two validation dialects and a durable consistency tax for reviewers.
- How can I validate Laravel config files with nette/schema?
- Define an Expect::structure schema for the config shape, process the loaded config array, and let the library normalize types and merge defaults. Catch ValidationException and map its messages into your config error output. Be aware that default() does not fire on present-but-null keys, so document that behavior for your team. A small config adapter is usually a one-to-two engineer-day spike.
- Can nette/schema validate JSON API payloads and hydrate DTOs?
- Yes. Decode the JSON payload, process it through your Expect schema, and use the normalized result to hydrate a DTO or command object. Because validation is exception-based, catch ValidationException and map messages to a 422 response or your API error format. If your API contract lives in OpenAPI, be careful that hand-written schemas do not become a second invisible source of truth that drifts from client-facing documentation.
- Is nette/schema's license safe for commercial Laravel applications?
- GitHub currently reports the license as NOASSERTION because its classifier did not recognize the license file. The Nette ecosystem is conventionally BSD-3-Clause, but you should not adopt the package until legal explicitly clears it and records that decision in your architecture decision record. If clearance fails, evaluate opis/json-schema when OpenAPI is your source of truth, or respect/validation as an alternative.
- What are the known gotchas when using nette/schema?
- Expect::array() strips numeric keys, which can cause silent data loss if you expect list semantics. default() does not fire on keys that are present but null, and transform() should not be used for side effects. Deploying an overly strict schema to live clients is also a self-inflicted outage vector, so evolve schemas additively. These are training and code-review controls rather than blockers.
- What are alternatives to nette/schema for Laravel projects?
- Laravel's built-in Validator and FormRequest are the default alternatives and integrate natively with requests, MessageBag, and 422 responses. opis/json-schema is a better fit when OpenAPI or JSON Schema is the contract of record. respect/validation is another general-purpose option. Choose based on whether you need request integration, contract-driven validation, or reusable schema-as-code across config, DTOs, and CLI.
- Is nette/schema actively maintained and safe to depend on?
- It is effectively a single-maintainer project, but it is a transitive dependency of nette/di, nette/application, Latte, and much of the PHP ecosystem, so its real install base is much larger than the low dependent count suggests. Abandonment risk is low and fork cost is small because the public surface is small and stable. Direction risk is non-zero, so pin the version, monitor releases, and keep an internal fork path documented.