PHPackages                             mleczek/laravel-negotiator - 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. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. mleczek/laravel-negotiator

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

mleczek/laravel-negotiator
==========================

Content negotiation for Laravel API

v1.0.1(9y ago)112MITPHP

Since Jan 20Pushed 9y ago1 watchersCompare

[ Source](https://github.com/mleczek/laravel-negotiator)[ Packagist](https://packagist.org/packages/mleczek/laravel-negotiator)[ Docs](https://github.com/mleczek/laravel-negotiator)[ RSS](/packages/mleczek-laravel-negotiator/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependencies (6)Versions (3)Used By (0)

Content negotiation for Laravel API
===================================

[](#content-negotiation-for-laravel-api)

[![Build Status](https://camo.githubusercontent.com/c280b15eb22edf3a880536af3c8050ab57063a111c00d668ff96e1ae713ef3f0/68747470733a2f2f7472617669732d63692e6f72672f6d6c65637a656b2f6c61726176656c2d6e65676f746961746f722e737667)](https://travis-ci.org/mleczek/laravel-negotiator)[![Latest Stable Version](https://camo.githubusercontent.com/f68b1f971d71ec7b958cd00e1b42ec4582bdcc031d6815ae84953a52891777e0/68747470733a2f2f706f7365722e707567782e6f72672f6d6c65637a656b2f6c61726176656c2d6e65676f746961746f722f762f737461626c65)](https://packagist.org/packages/mleczek/laravel-negotiator)[![License](https://camo.githubusercontent.com/bc0796c2e607feda4bc2b9071492bfc029e7fc327ab921bdbfb2d001102ccaa5/68747470733a2f2f706f7365722e707567782e6f72672f6d6c65637a656b2f6c61726176656c2d6e65676f746961746f722f6c6963656e7365)](https://packagist.org/packages/mleczek/laravel-negotiator)

- [Installation](#installation)
- [Usage](#usage)
- [Extending](#extending)
- [Contributing](#contributing)
- [License](#license)

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

[](#installation)

Require this package with composer:

```
composer require mleczek/laravel-negotiator

```

In `config/app.php` add the `NegotiatorServiceProvider`:

```
'providers' => [
    Mleczek\Negotiator\NegotiatorServiceProvider::class,
]
```

Usage
-----

[](#usage)

Package provide `negotiate` macro for `ResponseFactory`:

```
public function show(User $user)
{
    return response()->negotiate($user);
}
```

The same result can be achieved using `Mleczek\Negotiator\ContentNegotiation` class:

```
public function __construct(ContentNegotiation $cn)
{
    $this->cn = $cn;
}

public function show(Request $request, User $user)
{
    return $cn->negotiate($request, $user);
}
```

For both `negotiate` method and macro there is also one parameter which override result for specified content types:

```
public function show(User $user)
{
    // Return static JSON for request which
    // contains "application/json" in "Accepts" header.
    return response()->negotiate($user, [
        'application/json' => '{"id":4}',
    ]);
}
```

By default package support `application/json` and `application/xml`. XML format is resolved using [`mleczek/xml`](https://github.com/mleczek/xml) package.

Extending
---------

[](#extending)

You can extend supported content types in `boot` method of any of your `ServiceProvider`:

```
public function boot(ContentNegotiation $negotiator)
{
    // The ContentNegotiation facade is also available
    $negotiator->extend('application/json', function () {
        return new JsonHandler();
    });
}
```

The first parameter accept content type (or array of content types) for which the specified handler should be used.

Handler must implement the `Mleczek\Negotiator\Contracts\ContentNegotiationHandler` interface.

Contributing
------------

[](#contributing)

Thank you for considering contributing! If you would like to fix a bug or propose a new feature, you can submit a Pull Request.

License
-------

[](#license)

The library is licensed under the [MIT license](https://opensource.org/licenses/MIT).

###  Health Score

27

—

LowBetter than 47% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity64

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 ~0 days

Total

2

Last Release

3448d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/143e31568d2a8cef787b416fd2b5f10b78d28cb141ffe049c197d7fb31dc911c?d=identicon)[mleczek](/maintainers/mleczek)

---

Top Contributors

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

---

Tags

contentjsonlaravelnegotiationphpxmllaravelxmlcontentnegotiation

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3355.3M337](/packages/psalm-plugin-laravel)[laravel/socialite

Laravel wrapper around OAuth 1 &amp; OAuth 2 libraries.

5.7k108.5M846](/packages/laravel-socialite)[laravel/mcp

Rapidly build MCP servers for your Laravel applications.

77022.3M131](/packages/laravel-mcp)[spatie/laravel-responsecache

Speed up a Laravel application by caching the entire response

2.8k8.7M64](/packages/spatie-laravel-responsecache)[intervention/image-laravel

Laravel Integration of Intervention Image

1588.9M161](/packages/intervention-image-laravel)[bmatovu/laravel-xml

Laravel XML Support

91288.2k](/packages/bmatovu-laravel-xml)

PHPackages © 2026

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