PHPackages                             cyberpunkcodes/laravel-ajax-json-api - 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. cyberpunkcodes/laravel-ajax-json-api

ActiveLibrary[API Development](/categories/api)

cyberpunkcodes/laravel-ajax-json-api
====================================

Laravel AJAX JSON API

v1.0.0(2y ago)015MITPHPPHP ^7.2|^8.0

Since Oct 1Pushed 2y ago1 watchersCompare

[ Source](https://github.com/CyberPunkCodes/laravel-ajax-json-api)[ Packagist](https://packagist.org/packages/cyberpunkcodes/laravel-ajax-json-api)[ Docs](https://github.com/CyberPunkCodes/laravel-flashmessages)[ RSS](/packages/cyberpunkcodes-laravel-ajax-json-api/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (2)Versions (2)Used By (0)

Laravel AJAX JSON API
=====================

[](#laravel-ajax-json-api)

Turn your Laravel application into an AJAX JSON API.

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

[](#installation)

Install using Composer:

```
composer require cyberpunkcodes/laravel-ajax-json-api
```

This package will automatically be injected to your `api` middleware thanks to the Laravel ServiceProvider via:

```
$kernel->prependMiddlewareToGroup('api', ForceJson::class);
$kernel->prependMiddlewareToGroup('api', AjaxOnly::class);

$kernel->prependToMiddlewarePriority(ForceJson::class);
$kernel->prependToMiddlewarePriority(AjaxOnly::class);
```

You do not have to do anything other than use/apply the `api` middleware. The above lines are just to show you how the magic happens, by prepending `ForceJson` and `AjaxOnly` to the `api` middleware group, and adjusting their priority to be first.

Other than installing with Composer, all you have to do is use the `api` middleware. This could be in your Controller or wherever you need.

Ideally, in a sole AJAX JSON API, it would be applied globally to the entire application. This would be done in your `app/Providers/RouteServiceProvider.php`.

Example `RouteServiceProvider.php`:

```
