我有一个类,我正在注入一个控制器以及一个路由参数。然后我使用setter来设置类中的路由参数。构造函数注入路由参数
路线
Route::get('path/of/url/with/{paramVar}', '[email protected])
控制器
class testController
{
public function testFunc(MyClassInterface $class, $routeParamVar)
{
$class->setParam($routeParamVar);
//do stuff here
...
服务提供商
public function register()
{
$this->bind('path\to\interface', 'path\to\concrete');
}
我反而喜欢路线参数注入类的构造函数,我注入我的控制器。我知道我需要使用laravel容器的from this question。
我可以使用Request::class
注入其他路由参数,但是如何注入路由路径参数?
我想我会落得这样的
class testController
{
public function testFunc(MyClassInterface $class)
{
//do stuff here
...
你能举一些例子吗?或者显示完整的testController代码? – smartrahat
我已更新该问题并提供更多信息 – myol