PHPackages                             teepluss/restable - 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. teepluss/restable

ActiveLibrary[API Development](/categories/api)

teepluss/restable
=================

Laravel RESTful API format

2.0.1(11y ago)7467.5k↓50%11[3 PRs](https://github.com/teepluss/laravel-restable/pulls)MITPHPPHP &gt;=5.3.0

Since Jan 12Pushed 9y ago4 watchersCompare

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

READMEChangelogDependenciesVersions (6)Used By (0)

RESTful format response for Laravel
-----------------------------------

[](#restful-format-response-for-laravel)

### For Laravel 4, please use the [v1.x branch](https://github.com/teepluss/laravel-restable/tree/v1.x)!

[](#for-laravel-4-please-use-the-v1x-branch)

Restable is a useful to create RESTful API response format that support multiple format, such as Json, XML Serialized, PHP.

### Installation

[](#installation)

- [Restable on Packagist](https://packagist.org/packages/teepluss/restable)
- [Restable on GitHub](https://github.com/teepluss/laravel-restable)

To get the lastest version of Theme simply require it in your `composer.json` file.

```
"teepluss/restable": "dev-master"

```

You'll then need to run `composer install` to download it and have the autoloader updated.

Once Theme is installed you need to register the service provider with the application. Open up `config/app.php` and find the `providers` key.

```
'providers' => array(

    'Teepluss\Restable\RestableServiceProvider'

)

```

Restable also ships with a facade which provides the static syntax for creating collections. You can register the facade in the `aliases` key of your `config/app.php` file.

```
'aliases' => array(

    'Restable' => 'Teepluss\Restable\Facades\Restable'

)

```

Publish config using artisan CLI.

```
php artisan vendor:publish

```

Usage
-----

[](#usage)

API RESTful format.

Example:

```
use Teepluss\Restable\Contracts\Restable;

class ApiBlogsController extends BaseController {

    protected $rest;

    /**
     * Checking permission.
     *
     * @return Response
     */
    public function __construct(Restable $rest)
    {
        $this->rest = $rest;

        if ( ! Input::get('secret') == '12345')
        {
            return $this->rest->unauthorized()->render();
        }
    }

    /**
     * Display a listing of the resource.
     *
     * @return Response
     */
    public function index()
    {
        // Set default response format.
        //$this->rest->setDefaultFormat('xml');

        // Override format response.
        //return $this->rest->listing(Blog::paginate())->to('xml');
        //return $this->rest->listing(Blog::paginate())->toXML();

        return $this->rest->listing(Blog::paginate())->render();
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return Response
     */
    public function create()
    {
        return View::make('api.blogs.create');
    }

    /**
     * Store a newly created resource in storage.
     *
     * @return Response
     */
    public function store()
    {
        $blog = new Blog;

        $validator = Validator::make(Input::all(), array(
            'title'       => 'required',
            'description' => 'required'
        ));

        if ($validator->fails())
        {
            return $this->rest->unprocess($validator)->render();
        }

        $blog->title = Input::get('title');
        $blog->description = Input::get('description');

        $blog->save();

        return $this->rest->created($blog)->render();
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return Response
     */
    public function show($id)
    {
        $blog = Blog::find($id);

        if ( ! $blog)
        {
            return $this->rest->missing()->render();
        }

        return $this->rest->single($blog)->render();
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return Response
     */
    public function edit($id)
    {
        $blog = Blog::find($id);

        if ( ! $blog)
        {
            return $this->rest->missing()->render();
        }

        return View::make('api.blogs.edit', compact('blog'));
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  int  $id
     * @return Response
     */
    public function update($id)
    {
        $blog = Blog::find($id);

        if ( ! $blog)
        {
            return $this->rest->missing()->render();
        }

        $validator = Validator::make(Input::all(), array(
            'title'       => 'required',
            'description' => 'required'
        ));

        if ($validator->fails())
        {
            return $this->rest->unprocess($validator)->render();
        }

        $blog->title = Input::get('title');
        $blog->description = Input::get('description');

        $blog->save();

        return $this->rest->updated($blog)->render();
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return Response
     */
    public function destroy($id)
    {
        $blog = Blog::find($id);

        if ( ! $blog)
        {
            return $this->rest->missing()->render();
        }

        $blog->delete();

        return $this->rest->deleted()->render();
    }

}
```

Error cases.

```
// Unauthorized.
Restable::unauthorized()->render();

// Bad request.
Restable::bad()->render();

// Missing, Not found.
Restable::missing()->render();

// Unprocess, Validation Failed.
Restable::unprocess()->render();

// Custom.
Restable::error(null, 429)->render();
```

Another success cases.

```
return Restable::success()->render();
```

Changing error code.

```
return Restable::code(9001)->bad('message')->render();
```

Render to another format.

```
// XML
return Restable::single($data)->render('xml');

// Serialized
return Restable::single($data)->render('serialized');

// PHP
return Restable::single($data)->render('php');

// JSON
return Restable::single($data)->render('json');

// JSONP
return Restable::single($data)->render('json', Input::get('callback'));
// OR
return Restable::single($data)->toJson(Input::get('callback'));
```

Support or Contact
------------------

[](#support-or-contact)

If you have some problem, Contact

[![Support via PayPal](https://camo.githubusercontent.com/1c4c2a63b268ab949717893dda9628735444f61b8eb8eece283a534338b5b0e5/68747470733a2f2f7261776769746875622e636f6d2f63687269732d2d2d2f446f6e6174696f6e2d4261646765732f6d61737465722f70617970616c2e6a706567)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=9GEC8J7FAG6JA)

###  Health Score

38

—

LowBetter than 85% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity42

Moderate usage in the ecosystem

Community9

Small or concentrated contributor base

Maturity62

Established project with proven stability

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

Total

5

Last Release

4076d ago

Major Versions

1.0.2 → 2.0.02015-03-03

1.x-dev → 2.0.12015-03-21

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1464300?v=4)[Maximus](/maintainers/teepluss)[@teepluss](https://github.com/teepluss)

---

Tags

apilaravelrestful

### Embed Badge

![Health badge](/badges/teepluss-restable/health.svg)

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

PHPackages © 2026

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