- Can I use this package for Laravel API request validation like DTOs in Symfony?
- Yes, this package lets you create structured `VerifiedRequest` objects for API payloads, similar to Symfony DTOs. It validates nested data (arrays/objects) and integrates with Laravel’s `Validator` facade, making it ideal for APIs or form submissions.
- How do I install and set up `verified-request` in a Laravel project?
- Install via Composer: `composer require alex-dwt/verified-request`. Since it’s Symfony-based, you’ll need a Laravel adapter (e.g., a custom trait or facade) to bridge Symfony’s `ValidatorInterface` with Laravel’s `Validator`. The README lacks Laravel-specific setup, so check the GitHub issues for community solutions.
- Does this package support Laravel’s native validation rules (e.g., `#[Validate]` annotations)?
- No, it uses Symfony’s YAML/XML validation rules by default. You’ll need to manually convert them to Laravel’s array-based rules or annotations. For example, replace Symfony’s `required: true` with Laravel’s `'field' => 'required'` in your validation array.
- Will this work with Laravel 10+ and its latest validation features?
- The package’s core logic (request aggregation + validation) is framework-agnostic, but Symfony dependencies may require a Laravel wrapper. Test thoroughly with your Laravel version, as Symfony’s `Validator` might not align perfectly with Laravel’s latest `Validator` facade changes.
- How do validation errors work? Can I use Laravel’s `Validator::errors()`?
- Yes, the package integrates with Laravel’s `Validator` facade, so errors will return in Laravel’s standard format. Use `$validator->errors()` or `$request->validate()`-style error handling. No additional formatting is needed—it behaves like native Laravel validation.
- Is there a way to mock `VerifiedRequest` in PHPUnit for unit testing?
- Since it’s a Symfony-inspired class, mock the `VerifiedRequest` object like any other class in PHPUnit. Use `createMock(VerifiedRequest::class)` and define methods like `getData()` or `validate()`. For Laravel-specific testing, extend the class and override dependencies.
- Should I use this instead of Laravel’s built-in `FormRequest` classes?
- Use `verified-request` if you need DTO-like validation for APIs or complex nested data. For simple forms, Laravel’s `FormRequest` is lighter and more idiomatic. This package shines when you want reusable, validated request objects across controllers or services.
- Does this package support nested validation (e.g., arrays of objects)?
- Yes, it supports nested validation via Symfony’s constraints (e.g., `@Valid` for collections). In Laravel terms, this translates to recursive validation like `Validator::make($data, $rules)->validate()`. The package handles arrays/objects similarly to Laravel’s native `Validator`.
- How do I handle dependency injection in Laravel if this package uses Symfony’s DI?
- Bind `VerifiedRequest` classes manually in Laravel’s service container using `app()->bind()`. For example: `app()->bind(UserCreateRequest::class, function ($app) { return new UserCreateRequest($app['request']->all()); });`. Avoid Symfony’s full DI container—focus on the validator adapter.
- Are there performance concerns compared to Laravel’s native validation?
- Benchmark against `FormRequest` or `Validator::make()`—the overhead is minimal if you use a lightweight adapter. The package’s main cost is parsing Symfony-style rules, but Laravel’s native validation is already optimized. Test with your specific payload size.