PHPackages                             api-skeletons/laravel-api-problem - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [HTTP &amp; Networking](/categories/http)
4. /
5. api-skeletons/laravel-api-problem

ActiveLibrary[HTTP &amp; Networking](/categories/http)

api-skeletons/laravel-api-problem
=================================

Problem Details for HTTP APIs for Laravel

2.0.1(2y ago)118.4k↓33.3%3[1 PRs](https://github.com/API-Skeletons/laravel-api-problem/pulls)1BSD-3-ClausePHPPHP ^8.1

Since Jan 20Pushed 2y ago1 watchersCompare

[ Source](https://github.com/API-Skeletons/laravel-api-problem)[ Packagist](https://packagist.org/packages/api-skeletons/laravel-api-problem)[ Docs](https://apiskeletons.com)[ RSS](/packages/api-skeletons-laravel-api-problem/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (6)Dependencies (7)Versions (7)Used By (1)

API Problem for Laravel
=======================

[](#api-problem-for-laravel)

[![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)[![Code Coverage](https://camo.githubusercontent.com/06c7717807d35bffcab5415d4aacfb8439fb8e406fbd7479f760ce2a8f4c59f9/68747470733a2f2f636f6465636f762e696f2f67682f4150492d536b656c65746f6e732f6c61726176656c2d6170692d70726f626c656d2f6272616e63682f6d61696e2f6772617068732f62616467652e737667)](https://codecov.io/gh/API-Skeletons/laravel-api-problem/branch/main)[![PHP Version](https://camo.githubusercontent.com/22ba21bb30e83a7a9721060e56e895b2e88b17b6844a36b5dfb235bfc91260b5/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d382e312532622d626c7565)](https://img.shields.io/badge/PHP-8.1%2b-blue)[![Total Downloads](https://camo.githubusercontent.com/9fd50c6344f4ec977da9794be3bd4c2c8f8faa956ddc9bcc312aa0f4b8c79379/68747470733a2f2f706f7365722e707567782e6f72672f6170692d736b656c65746f6e732f6c61726176656c2d6170692d70726f626c656d2f646f776e6c6f616473)](//packagist.org/packages/api-skeletons/laravel-api-problem)[![License](https://camo.githubusercontent.com/02a39fb4dda9bad15ffd21c984e367bea1b9b6fe1547d7cf24d9677fe6b3da34/68747470733a2f2f706f7365722e707567782e6f72672f6170692d736b656c65746f6e732f6c61726176656c2d6170692d70726f626c656d2f6c6963656e7365)](//packagist.org/packages/api-skeletons/laravel-api-problem)

This repository implements [RFC 7807](https://www.rfc-editor.org/rfc/rfc7807.html)"Problem Details for HTTP APIs" for Laravel.

Installation
------------

[](#installation)

Run the following to install this library using [Composer](https://getcomposer.org/):

```
composer require api-skeletons/laravel-api-problem
```

Quick Start
-----------

[](#quick-start)

```
use ApiSkeletons\Laravel\ApiProblem\Facades\ApiProblem;

return ApiProblem::response('Detailed Unauthorized Message', 401);
```

This will result in a 401 response with header

```
Content-Type: application/problem+json
```

and content

```
{
    "type": "http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html",
    "title": "Unauthorized",
    "status": 401,
    "detail": "Detailed Unauthorized Messsge"
}
```

Use
---

[](#use)

### Using the facade

[](#using-the-facade)

You may use the ApiProblem object in two ways. First, you can use the facade to return a response quickly and directly as shown in the Quick Start. When using the facade the arguments to the `response()` method are:

```
response(
    string|Throwable $detail,
    int|string $status,
    ?string $type = null,
    ?string $title = null,
    array $additional = []
)
```

### Creating an object

[](#creating-an-object)

When creating an ApiProblem object directly, the first two parameters are swapped. The reason for this is the constructor for the original object remains unchanged and the `response()` function is modified to match the standard [Laravel response](https://laravel.com/docs/8.x/responses#response-objects)format.

```
__construct(
    int|string $status,
    string|Throwable $detail,
    ?string $type = null,
    ?string $title = null,
    array $additional = []
)
```

An example of creating an object directly:

```
use ApiSkeletons\Laravel\ApiProblem\ApiProblem;

$apiProblem = new ApiProblem(401, 'Detailed Unauthorized Message');
return $apiProblem->response();
```

Additional Details
------------------

[](#additional-details)

The 5th parameter to ApiProblem is $additional. This array adds adhoc properties to the JSON response. One method of using this array is a 422 response with details of the problem:

```
use ApiSkeletons\Laravel\ApiProblem\Facades\ApiProblem;
use Illuminate\Validation\ValidationException;

try {
    $validated = $request->validate([
        'title' => 'required|unique:posts|max:255',
        'body' => 'required',
    ]);
} catch (ValidationException $e) {
    return ApiProblem::response($e->getMessage(), 422, null, null, ['errors' => $e->errors()]);
}
```

results in:

```
{
    "errors":{
        "title":[
            "The title field is required."
        ],
        "body":[
            "The body field is required."
        ]
    },
    "type": "http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html",
    "title": "Unprocessable Entity",
    "status": 422,
    "detail": "The given data was invalid."
}
```

Use with the Exception Handler
------------------------------

[](#use-with-the-exception-handler)

```
namespace App\Exceptions;

use ApiSkeletons\Laravel\ApiProblem\Facades\ApiProblem;
use Doctrine\ORM\EntityNotFoundException;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Illuminate\Http\Request;

class Handler extends ExceptionHandler
{
    public function register(): void
    {
        $this->renderable(function (EntityNotFoundException $e, Request $request) {
            return ApiProblem::response($e->getMessage(), 404);
        });
    }
}
```

Attribution
-----------

[](#attribution)

The bulk of this repository was copied from Laminas API Tools. I wanted to provide a simplified interface specific to Laravel. Though the tool could have been used directly from the Laminas library it would have come with a lot of overhead.

###  Health Score

35

—

LowBetter than 80% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity31

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~163 days

Recently: every ~203 days

Total

6

Last Release

766d ago

Major Versions

0.0.2 → 1.0.02022-01-20

1.0.1 → 2.0.02024-04-12

PHP version history (2 changes)0.0.1PHP ^8.0

2.0.0PHP ^8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/49dd7d9dba889ac674b0da447d9c1e69d1128dc3ccbaef98ba83d6ee519fc2d6?d=identicon)[tom\_anderson](/maintainers/tom_anderson)

---

Top Contributors

[![TomHAnderson](https://avatars.githubusercontent.com/u/493920?v=4)](https://github.com/TomHAnderson "TomHAnderson (38 commits)")

---

Tags

laravelrestapi-problem

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Type Coverage Yes

### Embed Badge

![Health badge](/badges/api-skeletons-laravel-api-problem/health.svg)

```
[![Health](https://phpackages.com/badges/api-skeletons-laravel-api-problem/health.svg)](https://phpackages.com/packages/api-skeletons-laravel-api-problem)
```

###  Alternatives

[lomkit/laravel-rest-api

A package to build quick and robust rest api for the Laravel framework.

59152.2k](/packages/lomkit-laravel-rest-api)[francescomalatesta/laravel-api-boilerplate-jwt

An API Boilerplate to create a ready-to-use REST API in seconds.

1.2k7.5k](/packages/francescomalatesta-laravel-api-boilerplate-jwt)[api-platform/laravel

API Platform support for Laravel

59126.4k6](/packages/api-platform-laravel)[ably/ably-php-laravel

Ably realtime REST PHP library wrapper for Laravel

30319.6k1](/packages/ably-ably-php-laravel)[tartanlegrand/laravel-openapi

Generate OpenAPI Specification for Laravel Applications

38178.7k2](/packages/tartanlegrand-laravel-openapi)[xtend-packages/rest-presenter

REST API Presenter &amp; Generator for Laravel

771.5k](/packages/xtend-packages-rest-presenter)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
