Unresolvable dependency resolving [Parameter #0 [ $name ]]

后端 未结 3 1599
南方客
南方客 2020-12-11 00:23

Warning: This question is Laravel 4 specific.

I\'ve been using Facades in my controllers before. Therefore I know the code is working. Now I need to

相关标签:
3条回答
  • 2020-12-11 00:44

    For me it was just a matter of running

    php artisan optimize:clear
    
    0 讨论(0)
  • 2020-12-11 00:48

    Got it fixed. All the tutorials about dependency injection were referring to concrete implementations of interfaces so that I thought that's the way to go about it. Joseph Silber's answer got me on the right track.

    The trick is to bind the Interface to the binding of the ServiceProvider like shown below. That way Laravel will know how to instantiate the Helpers service.

    File: app/start/global.php

    <?php
    
    // ...
    
    App::bind('Acme\Interfaces\HelpersInterface', 'helpers');
    
    0 讨论(0)
  • 2020-12-11 00:58

    It seems your Acme\Services\Helpers constructor takes a $name parameter, but is not type hinted.

    Laravel's IoC is not magic. If your don't provide a type hint for every parameter, the IoC container has no way of knowing what to pass in.

    0 讨论(0)
提交回复
热议问题