3
votes

I am using lumen 7 framework. I had a bug. In the web.php file I put:

$router->get('/getAll/{param1:[0-9]+|2A|2B}/{param2:[0-9]+}', 'TestController@getAll');

So, in the TestController, I create the function like that :

  public function getAll($param1, $parm2)
{
    ....
}

The isssue is :

Illuminate\Contracts\Container\BindingResolutionException: Unable to resolve dependency [Parameter #1 [ $param2 ]] in class App\Http\Controllers\TestController

I did some tests, I add this bloc to provider, but it didn't work.

$this->app->singleton(\Illuminate\Contracts\Routing\ResponseFactory::class, function() {
return new \Laravel\Lumen\Http\ResponseFactory();

});

Also, I checked if I had done something wrong in the web.php file but I changed the function in the controllers to :

      public function getAll($param1)
    {
        $parm2=1;
        ....
    }

and it works fine.

How can I fix this bug, because in the url I need the two params. Thanks,

2

2 Answers

2
votes

The issue was that the names in controller and in the route was not the same. The names in the controller was a little different from the route. I did a upgrade from lumen 5.6 to lumen 7.0 and I thinks since Lumen 5.8 the names must be the same.

1
votes

In route, you're passing only one param that's why you're getting this error.

$router->get('/getAll/{param1:[0-9]+|2A|2B}/{param2:[0-9]+}/{param2:[0-9]+|2A|2B}/{param2:[0-9]+}', 'TestController@getAll');

In controller.

public function getAll($param1, $param2)
{
    ....
}