- What is kwrz/twig-exception used for in Laravel?
- kwrz/twig-exception lets Laravel render exception and error pages through Twig templates instead of Blade. It is aimed at applications that already use Twig for normal views and want custom error pages for specific routes or HTTP status codes. It does not replace Laravel's exception handler on its own; you need to wire it into the exception rendering path.
- Does kwrz/twig-exception work in a standard Blade-based Laravel application?
- Not natively. Laravel's exception flow is built around App\Exceptions\Handler, render and renderable hooks, middleware, and Blade views, so this package introduces a parallel Twig rendering path. It only makes sense if your app already uses Twig as a first-class engine, typically via something like twigbridge, or if you are prepared to build an adapter.
- Which Laravel and PHP versions are supported by kwrz/twig-exception?
- The package context does not document supported Laravel or PHP versions, and its weak adoption means you must verify compatibility yourself. Check the composer.json constraints for PHP, Twig, and Laravel, then run a time-boxed spike on your target versions. Do not assume current Laravel or Twig 3 support without testing.
- How do I install kwrz/twig-exception with Composer?
- Install it with composer require kwrz/twig-exception after confirming the version constraints match your PHP, Twig, and Laravel versions. Then wire the package into Laravel's exception handler or a middleware fallback rather than assuming it hooks in automatically. Publish or create any required configuration for route-specific and status-code mappings, and test with a non-production branch first.
- How do I create custom Twig error pages for specific HTTP status codes or routes?
- The package is intended to map routes or specific HTTP status codes to Twig exception templates. Configure those mappings in the package config or adapter layer, and keep Laravel's handler as the decision-maker for status codes. Test 403, 404, 419, 429, and 500 responses, and make sure a missing or broken Twig template falls back to Laravel's default error page.
- Can kwrz/twig-exception preserve JSON responses for API requests?
- That is not guaranteed by the package context, so you should not route API errors through Twig blindly. Keep Laravel's exception handler responsible for content negotiation and only delegate HTML rendering to Twig when the request expects HTML. Add tests that send Accept: application/json and confirm API clients still receive JSON error payloads.
- How does kwrz/twig-exception integrate with Laravel's App\Exceptions\Handler?
- It requires an adapter layer. Laravel's native flow centers on App\Exceptions\Handler, render(), renderable(), middleware, and Blade, and this package is Twig-oriented rather than a drop-in Laravel exception handler. Use it only as an HTML rendering delegate behind your existing handler, and preserve Laravel's reporting, logging, and status-code decisions.
- Is kwrz/twig-exception safe to use in production?
- Treat it as high risk until you have reviewed it. The package has zero stars, zero dependents, and a score of 0, so there is little ecosystem validation, and unsafe exception-page behavior can leak stack traces or exception messages in production. Ensure debug mode is off, template path resolution is reviewed, failures fall back to Laravel defaults, and recursive rendering cannot loop.
- What are better alternatives to kwrz/twig-exception for custom Laravel error pages?
- In a Blade-first app, prefer Laravel-native resources/views/errors/{code}.blade.php, Handler::renderable(), or a small custom exception renderer. If you already standardize on Twig, use a maintained Twig bridge and implement exception rendering as a thin adapter. These options keep Laravel's exception lifecycle intact and avoid a parallel rendering path.
- How should I test and maintain kwrz/twig-exception in a Laravel project?
- Add tests for 403, 404, 419, 429, and 500 responses, API JSON requests, debug on and off, missing templates, and Twig rendering failures. Pin the package version, document an exit plan, and expect to fork, patch, or replace it because community support is effectively absent. Roll it out behind a feature flag or canary with rollback by config.