Laravel 5 : php artisan route:list Illuminate\Container\BindingResolutionException]

1.4k views Asked by At

When I use the command "php artisan route:list" I have this error

[Illuminate\Container\BindingResolutionException]
Unresolvable dependency resolving [Parameter #0 [ <required> $methods ]] in class Illuminate\Routing\Route

The command works nicely when I have

Route::get('/', 'WelcomeController@index');
Route::get('home', 'HomeController@index');

but as soon as i add other routes, I have this exception

I found the problem :

I'm doing IOC in the controller and I inject Illuminate\Routing\Route. As soon as i delete the injection its works.

I have BaseController which extends Controller.

The BaseController is

class BaseController extends Controller {

/**
 * @var array Options used by the pages
 */
protected $options;

/**
 * @param Route $route
 */
public function __construct(Route $route)
{
    $this->options = Option::getAutoloaded();

    // Load the options for the named route page
    $this->options = array_merge($this->options, Option::getByPage($route->getAction()['as']));

    $this->initListPlugins();
}

A controller is

class MediasController extends BaseController {


public function __construct(Route $route)
{
    parent::__construct($route);

    $this->options = array_merge($this->options, Option::getByPage('media'));
}

Now thre problem is how I fix it :)

Thanx for your help

1

There are 1 answers

2
Pex On

When ever I see this error I think of typo's, so make sure you recheck everything for those.

Just make sure your Route is linked to the correct Controller@function:

Route::get('medias', ['uses' => 'MediasController@getMediaList', 'as' => 'medias.index']) 

Would go to the MediasController in Http/Controllers:

class MediasController extends Controller {

public function getMediaList()
{
    return view('medialist');
}

}

Also make sure your controller has a correct return to the view. And if you're using the

{!! link_to_route('medias.index', 'Media list') !!} 

make sure you have the "illuminate/html": "5.0.*@dev" installed through your composer.json aswell.