Is it possible to inject a route-paramter (or an route segment) to the controller-constructor?
You find some code to clarify my question.
class TestController{
protected $_param;
public function __construct($paramFromRoute)
{
$this->param = $paramFromRoute;
}
public function testAction()
{
return "Hello ".$this->_param;
}
}
----------------------------------------------------
App::bind('TestController', function($app, $paramFromRoute){
$controller = new TestController($paramFromRoute);
return $controller;
});
----------------------------------------------------
// here should be some magic
Route::get('foo/{bar}', 'TestController');
In Laravel 5.4, you can use this to request the parameter:
Laravel 5.3.28
You can't inject the parameter... But, you can inject the request and get it from the router instance, like this:
It's not possible to inject them, but you have access to all of them via:
http://www.golaravel.com/laravel/docs/5.1/container/