Great job. Can you give me an idea how to extend lumen route or app class? eg: I want like this $app->resource('my', 'MyController'); Described on another thread https://laracasts.com/discuss/channels/requests/lumen-resource-routing
Apr 24, 2015
7
Level 3
Lumen - Get Route Parameters Value.
Here's a simple snippet that gives access to route parameter's value.
This is present in Laravel but was missing in Lumen. Would be good if it's integrated to the core but until that happens, this works fine!
<?php // app/helpers.php
if (!function_exists('route_parameter')) {
/**
* Get a given parameter from the route.
*
* @param $name
* @param null $default
* @return mixed
*/
function route_parameter($name, $default = null)
{
$routeInfo = app('request')->route();
return array_get($routeInfo[2], $name, $default);
}
}
Create a app/helpers.php file and then load this in composer by adding it under autoload. Ex:
"autoload": {
"psr-4": {
"App\\": "app/"
},
"classmap": [
"database/"
],
"files": [
"app/helpers.php"
]
},
Make sure to composer dump-autoload. ($ composer du).
Please or to participate in this conversation.