PHPackages                             larafun/middleware - 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. [Framework](/categories/framework)
4. /
5. larafun/middleware

ActiveLibrary[Framework](/categories/framework)

larafun/middleware
==================

A collection middlewares to boost your Laravel development process

05PHP

Since Mar 15Pushed 7y agoCompare

[ Source](https://github.com/larafun/middleware)[ Packagist](https://packagist.org/packages/larafun/middleware)[ RSS](/packages/larafun-middleware/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependenciesVersions (1)Used By (0)

Larafun Middleware
==================

[](#larafun-middleware)

[![Build Status](https://camo.githubusercontent.com/2271b4dbb1ae3ba081cec96ed43d54c9c2f5c926c72ebc07694242e042ddcd1c/68747470733a2f2f7472617669732d63692e6f72672f6c61726166756e2f6d6964646c65776172652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/larafun/middleware)[![Latest Stable Version](https://camo.githubusercontent.com/1020064c4f3f082877c0ccf7c950ed36774267e7264f962b2fbcb8b14bd631ba/68747470733a2f2f706f7365722e707567782e6f72672f6c61726166756e2f6d6964646c65776172652f762f737461626c65)](https://packagist.org/packages/larafun/middleware)[![License](https://camo.githubusercontent.com/b1b395e28a942ab34da0e273277a75f7f9fa01a44abcfc41226cd018a6bb23f3/68747470733a2f2f706f7365722e707567782e6f72672f6c61726166756e2f6d6964646c65776172652f6c6963656e7365)](https://packagist.org/packages/larafun/middleware)[![Total Downloads](https://camo.githubusercontent.com/328061616ee7c29af38a9f2a82a328397474696e8775d6e49adb80f5f14a6660/68747470733a2f2f706f7365722e707567782e6f72672f6c61726166756e2f6d6964646c65776172652f646f776e6c6f616473)](https://packagist.org/packages/larafun/middleware)

On various occasions Laravel will check if the `Request` `wantsJson()` to determine the type of `Response` it needs to build. If the check does not pass, Laravel might return with redirects (in case of `ValidationException`) or with some pretty Blade templates (in case of `404 Responses`). These are all great features, but when you use Laravel to build your JSON APIs, you might want to respond with JSON messages when your API endpoints are being called.

This package offers an `AcceptJsonMiddleware` that will add the `application/json` Accept Header to all your requests, so that the `Request::wantsJson()` method will validate it. This middleware does not overwrite the existing media types present in the Accept Header, but in case of equal qualities will make sure that the `Request::wantsJson()` will pass.

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

[](#installation)

Requires PHP &gt; 7.0, Laravel &gt; 5.5

```
composer require larafun/middleware
```

Basic Usage
-----------

[](#basic-usage)

Just add the `AcceptJsonMiddleware` to your `App\Http\Kernel` class:

```
class Kernel extends HttpKernel
{
    protected $middlewareGroups = [
        // ...
        'api'   => [
            'accept-json',
            'throttle:60,1',
            'bindings'
        ]
    ];

    protected $routeMiddleware = [
        // ...
        'accept-json'   => \Larafun\Middleware\AcceptJsonMiddleware::class,
    ];
}
```

404 Not Found
-------------

[](#404-not-found)

Since the 404 message is triggered when no routes have been matched with the requested URL, placing the Middleware in a Route group will not apply it. If you also want your 404 messages to be handled as JSON, you can either use the [Laravel Fallback Routes](https://laravel.com/docs/5.8/routing#fallback-routes), or place the Middleware as the first item in the `$middleware` property of your `Kernel`.

```
class Kernel extends HttpKernel
{
    protected $middleware = [
        \Larafun\Middleware\AcceptJsonMiddleware::class,
        // ...
    ];
}
```

Changing Quality
----------------

[](#changing-quality)

In the rare case you might want a different quality for your `application/json` header, just pass it as a parameter in your `Kernel`.

```
class Kernel extends HttpKernel
{
    protected $middlewareGroups = [
        // ...
        'api'   => [
            'accept-json:0.8',
            //...
        ]
    ];
}
```

You should be aware that HTTP server configuration might add some default Accept Headers with quality 1. In this case, your settings will never take effect if you provide a lower quality. For best results you stick with the default quality setting.

Existing Header
---------------

[](#existing-header)

If the request already has an `application/json` Accept Header this Middleware will not overwrite it and maintain the consumer request quality.

You can force your new quality, passing the `force` string as the second parameter.

```
class Kernel extends HttpKernel
{
    protected $middlewareGroups = [
        // ...
        'api'   => [
            'accept-json:1,force',
            //...
        ]
    ];
}
```

###  Health Score

19

—

LowBetter than 10% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity38

Early-stage or recently created project

 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.

### Community

Maintainers

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

---

Top Contributors

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

### Embed Badge

![Health badge](/badges/larafun-middleware/health.svg)

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

###  Alternatives

[laravel/telescope

An elegant debug assistant for the Laravel framework.

5.2k67.8M192](/packages/laravel-telescope)[spiral/roadrunner

RoadRunner: High-performance PHP application server and process manager written in Go and powered with plugins

8.4k12.2M84](/packages/spiral-roadrunner)[nolimits4web/swiper

Most modern mobile touch slider and framework with hardware accelerated transitions

41.8k177.2k1](/packages/nolimits4web-swiper)[laravel/dusk

Laravel Dusk provides simple end-to-end testing and browser automation.

1.9k36.7M259](/packages/laravel-dusk)[laravel/prompts

Add beautiful and user-friendly forms to your command-line applications.

708181.8M596](/packages/laravel-prompts)[cakephp/chronos

A simple API extension for DateTime.

1.4k47.7M121](/packages/cakephp-chronos)

PHPackages © 2026

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