cyber-duck/restrouter

This package is abandoned and no longer maintained. The author suggests using the cyber-duck/restrouter package instead.

0.0.1 2014-09-02 13:48 UTC

This package is auto-updated.

Last update: 2023-09-08 11:30:56 UTC


README

This functionality is redily available in later versions of Laravel using Route::resource().

Laravel REST Routes

An extension to the Laravel Router to add an extra method ->rest() which creates RESTful routes similar to Laravel's built in resource.

Installation

Add the package to your composer.json and run composer update.

{
    "require": {
        "cyber-duck/restrouter": "dev-master"
    }
}

Add the service provider in app/config/app.php:

'CyberDuck\RestRouter\RestRouterServiceProvider',

This will add our route class to the IoC container in place of the default, everything will work as standard with the addition of Route::rest()

Example Usage

[app/routes.php]

<?php
$options = ['model' => 'ResourceModel'];
Route::rest('resource-name', 'ResourceController', ['model' => 'Models\Resource']);

This is will register the following routes:

URI Name Action
GET HEAD resource-name resource.index
POST resource-name resource.store ResourceController@store
GET HEAD resource-name/{models_resource}/{_path?} resource.show
PUT resource-name/{models_resource}/{_path?} resource.replace ResourceController@replace
PATCH resource-name/{models_resource}/{_path?} resource.update ResourceController@update
DELETE resource-name/{models_resource}/{_path?} resource.destroy ResourceController@destroy
GET HEAD POST

{_path} will capture the remainder of the path after matching the first part. The controller is also RESTful if you need to add any additional routes.

Options include model, except and only and work the same as resource()