- What is pretorien/request used for in a Laravel application?
- pretorien/request is a Laravel package that moves HTTP request handling into reusable, testable classes. You use it to validate, authorize, and transform incoming request data so controllers stay lean, and it also covers sending public HTTP requests, optionally through a proxy. It is most useful when the same request logic is repeated across controllers or needs to be covered by unit tests.
- How do I install pretorien/request with Composer?
- Install it with composer require pretorien/request. On current Laravel versions the service provider is usually discovered automatically; on older setups you may need to register it in config/app.php. After installing, check the repository README for any publishable configuration or environment variables, especially if you plan to route requests through a proxy.
- Which Laravel and PHP versions does pretorien/request support?
- Version support is declared in the package composer.json, so the Packagist page or the require block in the repository is the most reliable source. Check the laravel/framework and php constraints there before installing, and run composer why-not pretorien/request if Composer blocks the install. Pinning a release that matches your Laravel version avoids surprises during upgrades.
- How do I send an HTTP request through a proxy with this package?
- The package is described as sending public HTTP requests directly or through a proxy, which means proxy usage is configured rather than hardcoded per call. In practice you set the proxy address and any credentials in your configuration or environment file, then let the package route the request through it. Check the README for the exact configuration keys, and keep proxy credentials out of version control.
- Can I write tests for request handling built with pretorien/request?
- Because the request logic lives in dedicated classes instead of controller closures, you can instantiate those classes directly in PHPUnit or Pest and assert on validation, authorization, and transformed output. For outgoing calls, Laravel helpers such as Http::fake() let you assert what was sent without hitting a real endpoint. That combination keeps both incoming and outgoing request behaviour testable in isolation.
- How is pretorien/request different from Laravel Form Requests?
- Laravel Form Requests focus on validating and authorizing incoming requests, and they do that well. This package extends the idea to data transformation and to outgoing HTTP requests, including proxy support, keeping that logic in reusable classes. If you only need validation rules, native Form Requests may be enough; if you want a single, testable home for request handling, this package is the broader option.
- How do I handle validation errors and custom error messages?
- Validation failures typically surface through Laravel standard ValidationException, which produces a 422 JSON response or a redirect back with errors. You control rules, messages, and attribute names inside your request class, following the same conventions as native Form Requests. For fully custom responses, catch the exception in your exception handler or use the framework rendering hooks.
- Can I use pretorien/request outside of Laravel?
- It is built as a Laravel package, so its natural home is a Laravel application where the service provider and framework helpers are available. Individual classes may work in plain PHP if they carry no framework dependencies, but that is not the documented use case. If you need framework agnostic HTTP handling, a PSR-18 client or Guzzle is a safer choice.
- What are good alternatives to pretorien/request?
- Common alternatives include Laravel built-in Form Requests for validation and authorization, spatie/laravel-data for structured DTOs, and Saloon or Guzzle for outgoing HTTP calls. Many teams combine those rather than replacing one with another. Compare them on the features you actually need, such as proxy support, transformation, and testability.
- Is pretorien/request actively maintained and safe to use in production?
- Maintenance is best judged from the repository itself: recent commits, tagged releases, open issues, and whether composer.json targets current Laravel and PHP versions. For a smaller package, pin an exact version in composer.json and cover the parts you depend on with your own tests. That way a framework upgrade or an abandoned dependency will not silently break your request handling.