PHPackages                             malhal/laravel-restapi - 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. malhal/laravel-restapi

ActiveLibrary[Framework](/categories/framework)

malhal/laravel-restapi
======================

A controller and handler that lets you easily build a REST API

v1.0.0(9y ago)481MITPHPPHP &gt;=5.6.4

Since Sep 19Pushed 9y ago2 watchersCompare

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

READMEChangelogDependencies (1)Versions (2)Used By (0)

Laravel-RestApi
===============

[](#laravel-restapi)

A controller and handler that lets you easily build a REST API in Laravel that uses [fine grained CRUD resources](https://www.thoughtworks.com/insights/blog/rest-api-design-resource-modeling). It also provides consistent error responses using Laravel's built-in exception handling.

First in your model you want to use be sure to add a $fillable param with all the fields you would like to populate via the API methods, e.g.

```
protected $fillable = ['name', 'formattedAddress', 'latitude', 'longitude'];

```

Note this is important because it is also used to hide these fields from output when not needed. E.g. when a record is created we do not want to send the data back down to client. It would be much more complicated to reflect these fields from the database so we simply make use of this property.

Then, make a controller subclass of RestController, e.g. VenueController:

```
use Malhal\RestApi\RestController;

class VenueController extends RestController
{

}

```

Finally, in your api.php routes file add:

```
Route::resource('venue', 'VenueController',  ['except' => [
    'create', 'edit'
]]);

```

Now you can POST to api/venue to create a venue, PUT to replace it, or PATCH to update it. You can also use GET to query or api/venue/1 to get an individial record.

As an added bonus, to support batch updates add:

```
$this->post('batch', '\Malhal\RestApi\RestController@batch');

```

And post a JSON with a requests array like this:

```
{
    "atomic" : true,
    "requests":
    [
        {
            "url" : "api/venue/1000",
            "method" : "PUT",
            "body" : {
                "name" : "Test Venue"
                }
        },
        {
            "url" : "api/password",
            "method" : "POST",
            "body" : {
                "password" : "12345679",
                "venue_id" : 1000
                }
        }
    ]
}

```

And set the atomic flag to make it rollback if a request fails.

If you want to add validation then simply override a method and change the query if necessary, e.g.

```
class PasswordController extends RestController
{
    public function index(Request $request)
    {
        $this->validateQuery($request, [
            'venue_id' => 'required|integer'
        ]);
        return $this->newModel()->where('venue_id', $request->get('venue_id'))->get();
    }

    public function store(Request $request){
        $this->validateJson($request, [
            'venue_id' => 'required|integer'
        ]);
        return parent::store($request);
    }
}

```

Now if a password is posted and is missing a venue\_id then the following error is returned by the RestHandler:

```
{
  "error": "QueryException",
  "driverCode": "1364",
  "reason": "Field 'name' doesn't have a default value",
  "code": "HY000"
}

```

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

[](#installation)

[PHP](https://php.net) 5.6.4+ and [Laravel](http://laravel.com) 5.3+ are required.

To get the latest version of Laravel-RestApi, simply require the project using [Composer](https://getcomposer.org):

```
$ composer require malhal/laravel-restapi dev-master
```

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 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

Unknown

Total

1

Last Release

3520d ago

### Community

Maintainers

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

---

Top Contributors

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

---

Tags

apiframeworklaravelrestcontrollerMalcolm HallmalhalLaravel-RestApi

### Embed Badge

![Health badge](/badges/malhal-laravel-restapi/health.svg)

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

###  Alternatives

[malhal/laravel-geographical

Easily add longitude and latitude columns to your records and use inherited functionality for calculating distances

283375.6k](/packages/malhal-laravel-geographical)

PHPackages © 2026

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