PHPackages                             membrane/laravel - 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. [API Development](/categories/api)
4. /
5. membrane/laravel

ActiveLibrary[API Development](/categories/api)

membrane/laravel
================

1.7.0(1mo ago)41.6k3[1 issues](https://github.com/membrane-php/membrane-laravel/issues)MPL-2.0PHPPHP ^8.4CI passing

Since Dec 16Pushed 1mo ago2 watchersCompare

[ Source](https://github.com/membrane-php/membrane-laravel)[ Packagist](https://packagist.org/packages/membrane/laravel)[ RSS](/packages/membrane-laravel/feed)WikiDiscussions main Synced yesterday

READMEChangelog (10)Dependencies (22)Versions (16)Used By (0)

Membrane-Laravel
================

[](#membrane-laravel)

Integrates [Membrane-core](https://github.com/membrane-php/membrane-core) with [Laravel](https://laravel.com/).

About
-----

[](#about)

Middleware that validates the raw user input from incoming HTTP requests against your OpenAPI spec.
Adds a `Membrane\Result\Result` onto your `Illuminate\Contracts\Container\Container`.
The Result object contains the cleaned up data and additional details in the case of invalid requests.

Setup
-----

[](#setup)

### Installation

[](#installation)

Require the `membrane/laravel` package in your composer.json and update your dependencies:

```
composer require membrane/laravel
```

### Configuration

[](#configuration)

The defaults are set in `config/membrane.php`.
To publish a copy to your own config, use the following:

```
php artisan vendor:publish --tag="membrane"
```

#### API Spec File

[](#api-spec-file)

This is the **absolute** filepath of your OpenAPI.

By default, it looks for `/api/openapi.yaml`.

#### Validation Error Response Code

[](#validation-error-response-code)

Set `'validation_error_response_code'` to the **integer** value of the default http status code for invalid results.

#### Validation Error Response Type

[](#validation-error-response-type)

Set `'validation_error_response_type'` to the **string** value of the default response type for API problems.

#### API Problem Response Types

[](#api-problem-response-types)

Within the `'api_problem_response_types'` array: Set **integer** http status code =&gt; **string** response type pairs.
These are more specific and will override the default value set by `'validation_error_response_type'`

Usage
-----

[](#usage)

### Requests

[](#requests)

The `\Membrane\Laravel\Middleware\RequestValidation` middleware will validate or invalidate incoming requests and let you decide how to react. You can follow it with your own custom middleware or with one of the following built-in options to produce an error response:

### Responses

[](#responses)

Any response middleware MUST follow the `RequestValidation` middleware as it requires the `result` object being added to your container.
These middlewares will check whether the request has passed or failed validation.
Invalid requests will return an appropriate response detailing the reasons the request was invalid.

Your response can be in one of the following formats.

#### Flat Json

[](#flat-json)

`\Membrane\Laravel\Middleware\ResponseJsonFlat`

```
{
    "errors":{
        "pet->id":["must be an integer"],
        "pet":["name is a required field"]
    },
    "title":"Request payload failed validation",
    "type":"about:blank",
    "status":400
}
```

#### Nested Json

[](#nested-json)

`\Membrane\Laravel\Middleware\ResponseJsonNested`

```
{
    "errors":{
        "errors":[],
        "fields":{
            "pet":{
                "errors":[
                    "name is a required field"
                ],
                "fields":{
                    "id":{
                        "errors":[
                            "must be an integer"
                        ],
                        "fields":[]
                    }
                }
            }
        }
    },
    "title":"Request payload failed validation",
    "type":"about:blank",
    "status":400
}
```

### Global Usage

[](#global-usage)

To use any of the above middlewares on all routes, go into your `app/Http/Kernel.php` and add them to your `middleware`array.

For example:

```
protected $middleware = [
  \Membrane\Laravel\Middleware\RequestValidation::class,
  \Membrane\Laravel\Middleware\ResponseJsonFlat::class
  // ...
];
```

In Laravel 11.x/12.x `app/HttpKernel.php` has been removed, global configuration goes into `bootstrap/app.php`:

For example:

```
return Application::configure(basePath: dirname(__DIR__))
    // ...
    ->withMiddleware(function (Middleware $middleware) {
        // ...
        $middleware->appendToGroup('api', [
            \Membrane\Laravel\Middleware\RequestValidation::class,
            \Membrane\Laravel\Middleware\ResponseJsonFlat::class,
        ]);
    })
    // ...
    ->create();
```

###  Health Score

52

—

FairBetter than 96% of packages

Maintenance86

Actively maintained with recent releases

Popularity24

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity71

Established project with proven stability

 Bus Factor1

Top contributor holds 75.6% 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 ~125 days

Recently: every ~203 days

Total

11

Last Release

42d ago

PHP version history (3 changes)1.0.0PHP ^8.1.0

1.5.0PHP ^8.2.0

1.7.0PHP ^8.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/aee2ff8ab8a5dc8e25d2d59d9402f0395ab411fa46d99c25991857bcafba0639?d=identicon)[carnage](/maintainers/carnage)

![](https://www.gravatar.com/avatar/d2e97974be1030f8d2446744769198c26bb1050a02e594ae8d907e8aa408c7d1?d=identicon)[charjr](/maintainers/charjr)

---

Top Contributors

[![charjr](https://avatars.githubusercontent.com/u/102669158?v=4)](https://github.com/charjr "charjr (62 commits)")[![carnage](https://avatars.githubusercontent.com/u/846596?v=4)](https://github.com/carnage "carnage (17 commits)")[![philsturgeon](https://avatars.githubusercontent.com/u/67381?v=4)](https://github.com/philsturgeon "philsturgeon (2 commits)")[![mareg](https://avatars.githubusercontent.com/u/533217?v=4)](https://github.com/mareg "mareg (1 commits)")

---

Tags

laravelmembraneopenapiopenapi-validationopenapi3

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/membrane-laravel/health.svg)

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

###  Alternatives

[spatie/laravel-export

Create a static site bundle from a Laravel app

674146.0k6](/packages/spatie-laravel-export)[moonshine/moonshine

Laravel administration panel

1.3k253.1k81](/packages/moonshine-moonshine)[laravel/mcp

Rapidly build MCP servers for your Laravel applications.

77022.3M151](/packages/laravel-mcp)[mike-bronner/laravel-model-caching

Automatic caching for Eloquent models.

2.4k91.0k1](/packages/mike-bronner-laravel-model-caching)[psalm/plugin-laravel

Psalm plugin for Laravel

3355.3M345](/packages/psalm-plugin-laravel)[defstudio/telegraph

A laravel facade to interact with Telegram Bots

816333.6k3](/packages/defstudio-telegraph)

PHPackages © 2026

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