PHP code example of jonob / restful

1. Go to this page and download the library: Download jonob/restful library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

jonob / restful example snippets


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

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

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

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

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

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');

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

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

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');

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');