Download the PHP package timezhero/laravel-rfc9457 without Composer
On this page you can find all versions of the php package timezhero/laravel-rfc9457. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download timezhero/laravel-rfc9457
More information about timezhero/laravel-rfc9457
Files in timezhero/laravel-rfc9457
Package laravel-rfc9457
Short Description RFC 9457 Problem Details for Laravel exceptions
License
Homepage https://github.com/timezhero/laravel-rfc9457
Informations about the package laravel-rfc9457
Laravel RFC 9457
A Laravel package that standardizes API error responses using the RFC 9457 Problem Details specification. Exceptions opt in via a trait and PHP attributes — no base class required, no HTTP coupling on your domain exceptions.
Installation
Requires PHP 8.4+ and Laravel 11+.
The service provider is auto-discovered.
Quick start
1. Register the handler in bootstrap/app.php:
2. Scaffold an exception:
3. Throw it:
Response (409, application/problem+json):
Validation errors (with errors), authentication (401), HTTP exceptions, and generic 5xx are also wrapped automatically. 5xx responses never include the exception message.
CLI
| Command | What it does |
|---|---|
php artisan make:problem-exception {name} |
Creates exception class + translation entry + documentation view |
php artisan vendor:publish --tag=rfc9457-config |
Publish config |
php artisan vendor:publish --tag=rfc9457-views |
Publish views to customize the docs layout |
Advanced
Manual exception
#[Problem]— title + HTTP status, plus an optionaltype:URI. By default the type URI is{route_prefix}/{slug}, derived from the class name. Omit the attribute to derive everything (status defaults to 500)#[Extension]— marks properties as extension fields (snake_cased in output). Usename:to override the keydetail()— user-facing message (separate from internal$message). Return''to omitextensions()— override to add computed fields at runtime. Merged with attribute extensions
Translations
Convention-based in lang/{locale}/exceptions.php:
The key is always the snake_cased class name without Exception. Falls back to the raw #[Problem] title if no translation exists.
Documentation pages
Each exception gets a page at {route_prefix}/{slug} (default /problems/{slug}). Add a description view at resources/views/vendor/rfc9457/details/{slug}.blade.php. Extensions and metadata are rendered automatically.