PHPackages                             mmanos/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. [HTTP &amp; Networking](/categories/http)
4. /
5. mmanos/laravel-api

ActiveLibrary[HTTP &amp; Networking](/categories/http)

mmanos/laravel-api
==================

A RESTful API package for Laravel 5.

v2.0.0(10y ago)173713[3 issues](https://github.com/mmanos/laravel-api/issues)MITPHPPHP &gt;=5.3.0

Since Jan 14Pushed 10y ago2 watchersCompare

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

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

RESTful API package for Laravel 5
=================================

[](#restful-api-package-for-laravel-5)

This is an API package for the Laravel framework. It allows you to build a flexible RESTful API that can be consumed externally and by your own application.

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

[](#installation)

#### Composer

[](#composer)

Add this to you composer.json file, in the require object:

```
"mmanos/laravel-api": "dev-master"
```

After that, run composer install to install the package.

#### Service Provider

[](#service-provider)

Register the `Mmanos\Api\ApiServiceProvider` in your `app` configuration file.

#### Class Alias

[](#class-alias)

Add a class alias to `app/config/app.php`, within the `aliases` array.

```
'aliases' => array(
	// ...
	'Api' => 'Mmanos\Api\Api',
)
```

Laravel 4
---------

[](#laravel-4)

Use the `1.0` branch or the `v1.*` tags for Laravel 4 support.

Configuration
-------------

[](#configuration)

#### Publish config files and migrations

[](#publish-config-files-and-migrations)

Publish the `lucadegasperi/oauth2-server-laravel` config file and migrations to your application.

```
$ php artisan vendor:publish --provider="LucaDegasperi\OAuth2Server\OAuth2ServerServiceProvider"
```

Edit the published config file to fit your authentication needs. See this [configuration options](https://github.com/lucadegasperi/oauth2-server-laravel/wiki/Configuration-Options) page for information.

Publish the `mmanos/laravel-api` config file and migrations to your application.

```
$ php artisan vendor:publish --provider="Mmanos\Api\ApiServiceProvider"
```

And then run the migrations.

```
$ php artisan migrate
```

Add the following line to your `app/Http/Kernel.php` file in the `$middleware` array to catch any OAuth error and respond appropriately:

```
'LucaDegasperi\OAuth2Server\Middleware\OAuthExceptionHandlerMiddleware'
```

In order to make some the authorization and resource server work correctly with Laravel 5, remove the `App\Http\Middleware\VerifyCsrfToken` line from the `$middleware` array and place it in the $`routeMiddleware` array like this: `'csrf' => 'App\Http\Middleware\VerifyCsrfToken',`.

> **Note:** remember to add the csrf middleware manually on any route where it's appropriate.

#### Handling Exceptions

[](#handling-exceptions)

We need to modify the exception handler to properly format exceptions thrown by this package. Update the `App/Exceptions/Handler.php` file to use the exception handler from this package.

```
use Exception;
use Mmanos\Api\Exceptions\Handler as ExceptionHandler;

class Handler extends ExceptionHandler {
	...
}
```

Then add the `Mmanos\Api\Exceptions\HttpException` exception class to the `$dontReport` array so regular HTTP Exceptions are not reported.

Controllers
-----------

[](#controllers)

#### Configuration

[](#configuration-1)

Add the `ControllerTrait` to each of your API controllers. You could optionally add this to a BaseController extended by all of your other controllers.

```
use Illuminate\Routing\Controller;
use Mmanos\Api\ControllerTrait;

class BaseController extends Controller
{
	use ControllerTrait;
}
```

#### Pagination

[](#pagination)

If you return a pagination object from your controller action this package will add the following headers to the response:

- Pagination-Page
- Pagination-Num
- Pagination-Total
- Pagination-Last-Page

#### Setting custom response headers

[](#setting-custom-response-headers)

You may access the response object and set any additional headers directly from your controller action:

```
$this->response()->header('Example-Header', 'Example value');
```

#### Errors

[](#errors)

Dealing with errors when building your API is easy. Simply use the `Api::abort` method to throw an exception that will be formatted in a useful manner.

Throw a 404 Not Found error:

```
Api::abort(404);
```

Or a 403 Access Denied error:

```
Api::abort(403);
```

Customize the error message:

```
Api::abort(403, 'Access denied to scope: users:write');
```

Pass the errors from a validation object to get a clean response with all validation errors:

```
Api::abort(422, $validator->errors());
```

#### Protecting your API endpoints

[](#protecting-your-api-endpoints)

You may use the `protect` route filter to ensure the request is authenticated:

```
$this->beforeFilter('protect');
```

Or you may call the `Api::protect()` method directly.

If this check fails, a call to `Api::abort(401)` is made resulting in an Unauthorized error response.

#### Checking scope access

[](#checking-scope-access)

Use the `checkscope` route filter to ensure the requested resource is accessible:

```
$this->beforeFilter('checkscope:users.write');
```

Or you may call the `Api::checkScope('users:write')` method directly.

If this check fails, a call to `Api::abort(403)` is made resulting in an Access Denied error response with the scope name.

#### Transforming output

[](#transforming-output)

Any model, collection, or pagination object returned by your controller action will be automatically sent through any bound transformer classes.

Transformers
------------

[](#transformers)

Transformers allow you to easily and consistently transform objects into an array. By using a transformer you can type-cast integers, type-cast booleans, and nest relationships.

#### Bind a class to a transformer

[](#bind-a-class-to-a-transformer)

```
Api::bindTransformer('User', 'Transformers\User');
```

#### Set a class property

[](#set-a-class-property)

Alternatively, you could add a `transformer` property to your class to be auto-recognized by this package:

```
class User extends Eloquent
{
	public $transformer = 'Transformers\User';
}
```

#### Creating a transformer class

[](#creating-a-transformer-class)

Ensure your transformer class has a `transform` static method:

```
namespace Transformers;

class User
{
	public function transform($object, $request)
	{
		$output = $object->toArray();
		$output['id'] = (int) $output['id'];
		$output['created_at'] = $object->created_at->setTimezone('UTC')->toISO8601String();
		$output['updated_at'] = $object->updated_at->setTimezone('UTC')->toISO8601String();

		if ($request->input('hide_email')) {
			unset($output['email']);
		}

		return $output;
	}
}
```

Internal Requests
-----------------

[](#internal-requests)

A big part of this package is being able to perform requests on your API internally. This allows you to build your application on top of a consumable API.

#### Performing requests

[](#performing-requests)

Use the `Api::internal()` method to initiate an internal request:

```
$users_array = Api::internal('api/users')->get();
```

#### Passing extra parameters

[](#passing-extra-parameters)

```
$users_array = Api::internal('api/users', array('sort' => 'newest'))->get();
```

#### Specify HTTP method

[](#specify-http-method)

```
$new_user_array = Api::internal('api/users', array('email' => 'test@example.com'))->post();
```

CORS Support
------------

[](#cors-support)

CORS support is enabled by default, but only if the `Origin` header is detected. Adjust the settings in the config file to control the behavior and header values.

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance16

Infrequent updates — may be unmaintained

Popularity22

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity60

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

Total

3

Last Release

4003d ago

Major Versions

v1.0.0 → v2.0.02015-05-31

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/972055?v=4)[Mark Manos](/maintainers/mmanos)[@mmanos](https://github.com/mmanos)

---

Top Contributors

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

---

Tags

apilaravelrestserveroauthrestful

### Embed Badge

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

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

###  Alternatives

[api-platform/laravel

API Platform support for Laravel

59126.4k6](/packages/api-platform-laravel)[illuminatech/data-provider

Allows easy build for DB queries from API requests

4413.3k](/packages/illuminatech-data-provider)[guanguans/laravel-api-response

Normalize and standardize Laravel API response data structure. - 规范化和标准化 Laravel API 响应数据结构。

485.6k](/packages/guanguans-laravel-api-response)[ezralazuardy/heimdall

Painless OAuth 2.0 Server for CodeIgniter 4

454.2k](/packages/ezralazuardy-heimdall)[laragear/api-manager

Manage multiple REST servers to make requests in few lines and fluently.

161.8k](/packages/laragear-api-manager)

PHPackages © 2026

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