Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save pichotweb/fb4f91bd81f358c93d6efb6ee712b5cd to your computer and use it in GitHub Desktop.
Save pichotweb/fb4f91bd81f358c93d6efb6ee712b5cd 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');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment