{"id":29543178,"url":"https://github.com/api-skeletons/laravel-api-problem","last_synced_at":"2025-08-28T22:14:57.959Z","repository":{"id":44881399,"uuid":"450017266","full_name":"API-Skeletons/laravel-api-problem","owner":"API-Skeletons","description":"Problem Details for HTTP APIs for Laravel","archived":false,"fork":false,"pushed_at":"2024-04-13T02:58:03.000Z","size":98,"stargazers_count":11,"open_issues_count":1,"forks_count":3,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-08-19T08:16:49.006Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/API-Skeletons.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-01-20T08:39:05.000Z","updated_at":"2024-08-16T08:05:24.000Z","dependencies_parsed_at":"2022-09-10T03:24:01.983Z","dependency_job_id":null,"html_url":"https://github.com/API-Skeletons/laravel-api-problem","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/API-Skeletons/laravel-api-problem","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/API-Skeletons%2Flaravel-api-problem","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/API-Skeletons%2Flaravel-api-problem/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/API-Skeletons%2Flaravel-api-problem/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/API-Skeletons%2Flaravel-api-problem/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/API-Skeletons","download_url":"https://codeload.github.com/API-Skeletons/laravel-api-problem/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/API-Skeletons%2Flaravel-api-problem/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":272566652,"owners_count":24956620,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-28T02:00:10.768Z","response_time":74,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-07-17T13:08:42.824Z","updated_at":"2025-08-28T22:14:57.952Z","avatar_url":"https://github.com/API-Skeletons.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# API Problem for Laravel\n\n[![Build Status](https://github.com/API-Skeletons/laravel-api-problem/actions/workflows/continuous-integration.yml/badge.svg)](https://github.com/API-Skeletons/laravel-api-problem/actions/workflows/continuous-integration.yml?query=branch%3Amain)\n[![Code Coverage](https://codecov.io/gh/API-Skeletons/laravel-api-problem/branch/main/graphs/badge.svg)](https://codecov.io/gh/API-Skeletons/laravel-api-problem/branch/main)\n[![PHP Version](https://img.shields.io/badge/PHP-8.1%2b-blue)](https://img.shields.io/badge/PHP-8.1%2b-blue)\n[![Total Downloads](https://poser.pugx.org/api-skeletons/laravel-api-problem/downloads)](//packagist.org/packages/api-skeletons/laravel-api-problem)\n[![License](https://poser.pugx.org/api-skeletons/laravel-api-problem/license)](//packagist.org/packages/api-skeletons/laravel-api-problem)\n\nThis repository implements [RFC 7807](https://www.rfc-editor.org/rfc/rfc7807.html)\n\"Problem Details for HTTP APIs\" for Laravel.\n\n## Installation\n\nRun the following to install this library using [Composer](https://getcomposer.org/):\n\n```bash\ncomposer require api-skeletons/laravel-api-problem\n```\n\n## Quick Start\n\n```php\nuse ApiSkeletons\\Laravel\\ApiProblem\\Facades\\ApiProblem;\n\nreturn ApiProblem::response('Detailed Unauthorized Message', 401);\n```\n\nThis will result in a 401 response with header\n\n```shell\nContent-Type: application/problem+json\n```\n\nand content\n```json\n{\n    \"type\": \"http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html\",\n    \"title\": \"Unauthorized\",\n    \"status\": 401,\n    \"detail\": \"Detailed Unauthorized Messsge\"\n}\n```\n\n## Use\n\n### Using the facade\n\nYou may use the ApiProblem object in two ways.  First, you can use the facade to\nreturn a response quickly and directly as shown in the Quick Start.  When using\nthe facade the arguments to the `response()` method are:\n\n```php\nresponse(\n    string|Throwable $detail, \n    int|string $status, \n    ?string $type = null, \n    ?string $title = null, \n    array $additional = []\n)\n```\n\n### Creating an object\n\nWhen creating an ApiProblem object directly, the first two parameters are swapped.\nThe reason for this is the constructor for the original object remains unchanged\nand the `response()` function is modified to match the standard\n[Laravel response](https://laravel.com/docs/8.x/responses#response-objects)\nformat.\n\n```php\n__construct(\n    int|string $status, \n    string|Throwable $detail, \n    ?string $type = null, \n    ?string $title = null, \n    array $additional = []\n)\n```\n\nAn example of creating an object directly:\n\n```php\nuse ApiSkeletons\\Laravel\\ApiProblem\\ApiProblem;\n\n$apiProblem = new ApiProblem(401, 'Detailed Unauthorized Message');\nreturn $apiProblem-\u003eresponse();\n```\n\n## Additional Details\n\nThe 5th parameter to ApiProblem is $additional.  This array adds adhoc properties to the\nJSON response.  One method of using this array is a 422 response with details of the problem:\n\n```php\nuse ApiSkeletons\\Laravel\\ApiProblem\\Facades\\ApiProblem;\nuse Illuminate\\Validation\\ValidationException;\n\ntry {\n    $validated = $request-\u003evalidate([\n        'title' =\u003e 'required|unique:posts|max:255',\n        'body' =\u003e 'required',\n    ]);\n} catch (ValidationException $e) {\n    return ApiProblem::response($e-\u003egetMessage(), 422, null, null, ['errors' =\u003e $e-\u003eerrors()]);\n}\n```\n\nresults in:\n\n```json\n{\n    \"errors\":{\n        \"title\":[\n            \"The title field is required.\"\n        ],\n        \"body\":[\n            \"The body field is required.\"\n        ]\n    },\n    \"type\": \"http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html\",\n    \"title\": \"Unprocessable Entity\",\n    \"status\": 422,\n    \"detail\": \"The given data was invalid.\"\n}\n```\n\n## Use with the Exception Handler\n\n```php\nnamespace App\\Exceptions;\n\nuse ApiSkeletons\\Laravel\\ApiProblem\\Facades\\ApiProblem;\nuse Doctrine\\ORM\\EntityNotFoundException;\nuse Illuminate\\Foundation\\Exceptions\\Handler as ExceptionHandler;\nuse Illuminate\\Http\\Request;\n\nclass Handler extends ExceptionHandler\n{\n    public function register(): void\n    {\n        $this-\u003erenderable(function (EntityNotFoundException $e, Request $request) {\n            return ApiProblem::response($e-\u003egetMessage(), 404);\n        });\n    }\n}\n\n```\n\n## Attribution\n\nThe bulk of this repository was copied from Laminas API Tools.  I wanted to provide a\nsimplified interface specific to Laravel.  Though the tool could have been used directly\nfrom the Laminas library it would have come with a lot of overhead.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fapi-skeletons%2Flaravel-api-problem","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fapi-skeletons%2Flaravel-api-problem","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fapi-skeletons%2Flaravel-api-problem/lists"}