Skip to content

Instantly share code, notes, and snippets.

@sohelamin
Created April 20, 2015 18:34
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save sohelamin/a85329700f1ecae1b490 to your computer and use it in GitHub Desktop.
Save sohelamin/a85329700f1ecae1b490 to your computer and use it in GitHub Desktop.
Lumen Resource Routing
<?php
/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the controller to call when that URI is requested.
|
*/
$app->get('/', function() use ($app) {
return $app->welcome();
});
resource('my', 'MyController');
function resource($uri, $controller)
{
//$verbs = array('GET', 'HEAD', 'POST', 'PUT', 'PATCH', 'DELETE');
global $app;
$app->get($uri, 'App\Http\Controllers\\'.$controller.'@index');
$app->get($uri.'/create', 'App\Http\Controllers\\'.$controller.'@create');
$app->post($uri, 'App\Http\Controllers\\'.$controller.'@store');
$app->get($uri.'/{id}', 'App\Http\Controllers\\'.$controller.'@show');
$app->get($uri.'/{id}/edit', 'App\Http\Controllers\\'.$controller.'@edit');
$app->put($uri.'/{id}', 'App\Http\Controllers\\'.$controller.'@update');
$app->patch($uri.'/{id}', 'App\Http\Controllers\\'.$controller.'@update');
$app->delete($uri.'/{id}', 'App\Http\Controllers\\'.$controller.'@destroy');
}
@sohelamin
Copy link
Author

Controller should have the following methods:
index()
create()
store()
show($id)
edit($id)
update($id)
destroy($id)

@goodevilgenius
Copy link

create and edit are not relevant to APIs, and so should be left out of Lumen.

@amitshahc
Copy link

Thanks for this code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment