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.6.0(10mo ago)41.6k3[1 issues](https://github.com/membrane-php/membrane-laravel/issues)MPL-2.0PHPPHP ^8.2.0CI passing

Since Dec 16Pushed 10mo 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 1mo ago

READMEChangelog (10)Dependencies (11)Versions (14)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

41

—

FairBetter than 89% of packages

Maintenance49

Moderate activity, may be stable

Popularity23

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity66

Established project with proven stability

 Bus Factor1

Top contributor holds 75.9% 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 ~102 days

Recently: every ~122 days

Total

10

Last Release

314d ago

PHP version history (2 changes)1.0.0PHP ^8.1.0

1.5.0PHP ^8.2.0

### 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 (60 commits)")[![carnage](https://avatars.githubusercontent.com/u/846596?v=4)](https://github.com/carnage "carnage (16 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

[laravel/passport

Laravel Passport provides OAuth2 server support to Laravel.

3.4k85.0M531](/packages/laravel-passport)[spatie/laravel-export

Create a static site bundle from a Laravel app

646127.9k5](/packages/spatie-laravel-export)[kirschbaum-development/laravel-openapi-validator

Automatic OpenAPI validation for Laravel HTTP tests

581.1M5](/packages/kirschbaum-development-laravel-openapi-validator)[mll-lab/laravel-graphiql

Easily integrate GraphiQL into your Laravel project

683.2M9](/packages/mll-lab-laravel-graphiql)[esign/laravel-conversions-api

A laravel wrapper package around the Facebook Conversions API

69145.4k](/packages/esign-laravel-conversions-api)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

255.2k](/packages/aedart-athenaeum)

PHPackages © 2026

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