PHPackages                             jonob/restful - 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. jonob/restful

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

jonob/restful
=============

Restful, named and nested routes for Laravel 4

v1.0.0(13y ago)86741PHPPHP &gt;=5.3.0

Since Jan 13Pushed 13y ago1 watchersCompare

[ Source](https://github.com/JonoB/restful)[ Packagist](https://packagist.org/packages/jonob/restful)[ RSS](/packages/jonob-restful/feed)WikiDiscussions master Synced 1w ago

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

Restful routes for Laravel 4
============================

[](#restful-routes-for-laravel-4)

Create restful routes for Laravel 4, included nested controllers, named routes and custom templates. This greatly enhances the `Route::Resource` method currently available in Laravel 4, which currently offers none of these features.

Getting started
---------------

[](#getting-started)

### Composer

[](#composer)

Add `"jonob/restful": ">=1.0.*"` to the `require` section of your `composer.json`:

```
"require": {
	"jonob/restful": ">=1.0.*"
},

```

Now run `composer install`.

### Laravel

[](#laravel)

Add the following code to the `aliases` section of the `app/config/app.php` file

```
'Restful' => 'Jonob\Restful\Restful',
```

so that it looks something like the following:

```
'aliases' => array(
	...
	'Restful'       => 'Jonob\Restful\Restful',
	...
),
```

Adding Restful Routes
---------------------

[](#adding-restful-routes)

Restful Routes are created in app\\routes.php as follows:

```
// Create a new bunch of restful routes for the 'products' resource
new Restful('products', 'ProductsController');

// Or use the static method
Restful::make('products', 'ProductsController');
```

This will automatically create a whole bunch of restful routes for you as follows:

```
Route::get('products/{id}/edit', array('as' => 'ProductEdit', 'uses' => 'ProductsController@edit');
Route::get('products/add', array('as' => 'ProductAdd', 'uses' => 'ProductsController@create');
Route::get('products/{id}', array('as' => 'Product', 'uses' => 'ProductsController@show');
Route::get('products', array('as' => 'Products', 'uses' => 'ProductsController@index');
Route::post('products', array('as' => 'ProductStore', 'uses' => 'ProductsController@store');
Route::put('products/{id}', array('as' => 'ProductUpdate', 'uses' => 'ProductsController@update');
Route::delete('products/{id}', array('as' => 'ProductDelete', 'uses' => 'ProductsController@destroy');

```

Nested Routes
-------------

[](#nested-routes)

There are two main options for handling nested routes. You can either nest your controllers in sub-folders as well, or you can refer directly to the main controllers folder

#### Nested Controllers

[](#nested-controllers)

If you have nested controllers, then Restful can handle that too.

```
Restful::make('products.categories', 'products_CategoriesController');
```

Note here that the underscore represents a directory seperator, so we would expect the following:

```
// app/controllers/products/CategoriesController.php
class Products_CategoriesController extends SiteController
{
	...
}

```

This would create the following restful routes for you:

```
Route::get('products/{product_id}/categories/{id}/edit', array('as' => 'ProductCategoryEdit', 'uses' => 'products.CategoriesController@edit');
Route::get('products/{product_id}/categories/add', array('as' => 'ProductCommentAdd', 'uses' => 'products.CategoriesController@create');
Route::get('products/{product_id}/categories/{id}', array('as' => 'ProductCategory', 'uses' => 'products.CategoriesController@show');
Route::get('products/{product_id}/categories', array('as' => 'ProductCategories', 'uses' => 'products.CategoriesController@index');
Route::post('products/{product_id}/categories', array('as' => 'ProductCategoryAdd', 'uses' => 'products.CategoriesController@store');
Route::put('products/{product_id}/categories/{id}', array('as' => 'ProductCategoryUpdate', 'uses' => 'products.CategoriesController@update');
Route::delete('products/{product_id}/categories/{id}', array('as' => 'ProductCategoryDelete', 'uses' => 'products.CategoriesController@destroy');
```

#### Controllers in root controllers directory

[](#controllers-in-root-controllers-directory)

You can, of course, still have a nested route that routes to the main controllers folder if you wish:

```
Restful::make('products.categories', 'CategoriesController');

// app/controllers/CategoriesController.php
class CategoriesController extends SiteController
{
	...
}
```

This would create the following restful routes for you:

```
Route::get('products/{product_id}/categories/{id}/edit', array('as' => 'ProductCategoryEdit', 'uses' => 'CategoriesController@edit');
Route::get('products/{product_id}/categories/add', array('as' => 'ProductCommentAdd', 'uses' => 'CategoriesController@create');
Route::get('products/{product_id}/categories/{id}', array('as' => 'ProductCategory', 'uses' => 'CategoriesController@show');
Route::get('products/{product_id}/categories', array('as' => 'ProductCategories', 'uses' => 'CategoriesController@index');
Route::post('products/{product_id}/categories', array('as' => 'ProductCategoryAdd', 'uses' => 'CategoriesController@store');
Route::put('products/{product_id}/categories/{id}', array('as' => 'ProductCategoryUpdate', 'uses' => 'CategoriesController@update');
Route::delete('products/{product_id}/categories/{id}', array('as' => 'ProductCategoryDelete', 'uses' => 'CategoriesController@destroy');
```

Changing the route template
---------------------------

[](#changing-the-route-template)

Restful Routes uses a default template to create the above routes, but you can easily override this template to create your own routes by passing this as the third parameter.

```
Restful::make('products', 'ProductsController', $myTemplate);

```

###  Health Score

30

—

LowBetter than 62% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity20

Limited adoption so far

Community8

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

4895d ago

### Community

Maintainers

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

---

Top Contributors

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

---

Tags

laravelrestrouterestful

### Embed Badge

![Health badge](/badges/jonob-restful/health.svg)

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

###  Alternatives

[omniphx/forrest

A Laravel library for Salesforce

2744.6M9](/packages/omniphx-forrest)[api-platform/laravel

API Platform support for Laravel

59156.3k10](/packages/api-platform-laravel)[guanguans/laravel-api-response

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

486.1k](/packages/guanguans-laravel-api-response)[illuminatech/model-route

Allows continuing route matching in case bound model does not exist

111.2k](/packages/illuminatech-model-route)

PHPackages © 2026

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