Created
April 20, 2015 18:34
-
-
Save sohelamin/a85329700f1ecae1b490 to your computer and use it in GitHub Desktop.
Lumen Resource Routing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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'); | |
} |
create
and edit
are not relevant to APIs, and so should be left out of Lumen.
Thanks for this code.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Controller should have the following methods:
index()
create()
store()
show($id)
edit($id)
update($id)
destroy($id)