PHPackages                             randomstate/laravel-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. randomstate/laravel-api

ActiveLibrary[API Development](/categories/api)

randomstate/laravel-api
=======================

Integration of randomstate/api with Laravel

v2.1.0(4y ago)01.9k↓100%[3 PRs](https://github.com/randomstate/laravel-api/pulls)MITPHPPHP &gt;=8.0

Since Sep 6Pushed 3y ago1 watchersCompare

[ Source](https://github.com/randomstate/laravel-api)[ Packagist](https://packagist.org/packages/randomstate/laravel-api)[ RSS](/packages/randomstate-laravel-api/feed)WikiDiscussions master Synced 1mo ago

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

laravel-api
===========

[](#laravel-api)

Laravel Integration for randomstate/api.

**Note, for a framework agnostic starter, use randomstate/api. You will need to do some significant wiring up to make it as useful as this Laravel package.**

What it does
============

[](#what-it-does)

LaravelApi is an API versioning package that allows you to namespace and version your APIs (web, ajax, rest etc) easily. It comes with out of the box support and integration for the fantastic `league/fractal` package.

In essence, this package allows you to standardise the output of your API while maintaining flexibility; using namespaces to change context. Add to that the fact you can version your API responses to target particular users, and you have the start to a blissful API building experience.

Installation and Setup
======================

[](#installation-and-setup)

`composer require randomstate/laravel-api`

Add `\RandomState\LaravelApi\LaravelApiServiceProvider::class` to your app.php config file.

Publish the configuration file by running: `php artisan vendor:publish --tag=laravel-api`

Because of the deep routing integration required to make the magic work, you need to replace the Http Kernel with the one provided in this package. You should change the `app/Http/Kernel.php` class to extend `RandomState\LaravelApi\Http\Kernel` instead of the HttpKernel default.

### Namespace Setup

[](#namespace-setup)

To namespace your routes, you can utilise the `RandomsState\LaravelApi\Http\Middleware\ApiNamespace` middleware class. Add the following to the `$routeMiddleware` property on your Kernel class.

```
protected $routeMiddleware = [
    'auth' => \Illuminate\Auth\Middleware\Authenticate::class,
    // ...
    'namespace' => RandomsState\LaravelApi\Http\Middleware\ApiNamespace::class,
];
```

Usage
=====

[](#usage)

### Namespacing

[](#namespacing)

If you followed the setup instructions you will have added a 'namespace' middleware. You can use this as so:

```
Route::group(['middleware' => ['namespace:web'], function() {});
Route::group(['middleware' => ['namespace:web,1.0'], function() {}); // Forces version 1.0 to be used (must be specified in your laravel-api.php config file.
```

### Dynamic Versioning

[](#dynamic-versioning)

Since the intended use case for this package is to dynamically provide your API depending on your users' target version, I recommend the following way of versioning your routes automatically: In a service provider register method, (such as AppServiceProvider), you can add the following:

```
$this->app->bind(\RandomState\LaravelApi\VersionSwitch::class, function() {
    return new class implements \RandomState\LaravelApi\VersionSwitch::class {
        public function getVersionIdentifier() {
            return Auth::user()->getApiVersion();
        }
    }
});
```

**You must implement the storage and `getApiVersion` method yourself - this is just an example of how you could do it.**

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity77

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

Recently: every ~349 days

Total

17

Last Release

1709d ago

Major Versions

v0.3.6 → v1.0.02020-03-07

v1.0.0 → v2.0.02021-08-28

PHP version history (2 changes)v1.0.0PHP &gt;= 7.2.5

v2.0.0PHP &gt;=8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/1204796510f0f912ac6f85359e20efbc78e573c00c742a3a53f509f3abdc7f9f?d=identicon)[CImrie](/maintainers/CImrie)

---

Top Contributors

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

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[stripe/stripe-php

Stripe PHP Library

4.0k143.3M475](/packages/stripe-stripe-php)[twilio/sdk

A PHP wrapper for Twilio's API

1.6k92.9M270](/packages/twilio-sdk)[knplabs/github-api

GitHub API v3 client

2.2k15.8M187](/packages/knplabs-github-api)[facebook/php-business-sdk

PHP SDK for Facebook Business

90121.9M34](/packages/facebook-php-business-sdk)[meilisearch/meilisearch-php

PHP wrapper for the Meilisearch API

73813.7M114](/packages/meilisearch-meilisearch-php)[google/gax

Google API Core for PHP

263103.1M452](/packages/google-gax)

PHPackages © 2026

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