我收到这个错误:
BindingResolutionException in compiled.php line 1029:
Target [App\Models\Contracts\Repositories\IUserRepository] is not instantiable.
Run Code Online (Sandbox Code Playgroud)
我的代码如下:
接口:
namespace App\Models\Contracts\Repositories;
use App\Models\Objects\DTO\User;
interface IUserRepository
{
function Create( User $user );
}
Run Code Online (Sandbox Code Playgroud)
具体:
namespace App\Models\Concrete\Eloquent;
use App\Models\Contracts\Repositories\IUserRepository;
use App\Models\Objects\DTO\User;
class EqUserRepository implements IUserRepository
{
/**
* Create a new user instance after a valid registration.
*
* @param array $data
* @return User
*/
public function Create( User $user )
{
return User::create( [
'first_name' => $user->first_name,
'last_name' => $user->last_name,
'username' => $user->username,
'email' => $user->email, …Run Code Online (Sandbox Code Playgroud) 我的错误信息:
Illuminate \ Container \ BindingResolutionException
Target [Project\Backend\Service\Validation\ValidableInterface] is not instantiable.
Run Code Online (Sandbox Code Playgroud)
我知道接口和抽象类是不可实例化的,所以我知道Laravel不应该尝试实例化我的接口.但不知何故,它正在努力,我怀疑这可能是一个具有约束力的问题......即使我相信我已经正确绑定它并将其注册为服务提供商.
我应该提一下,我从Chris Fidao的"实施Laravel"中取出了这个例子,它几乎完全相同!
这是我的表单类的前几行:
namespace Project\Backend\Service\Form\Job;
use Project\Backend\Service\Validation\ValidableInterface;
use Project\Backend\Repo\Job\JobInterface;
class JobForm {
/**
* Form Data
*
* @var array
*/
protected $data;
/**
* Validator
*
* @var \Project\Backend\Form\Service\ValidableInterface
*/
protected $validator;
/**
* Job repository
*
* @var \Project\Backend\Repo\Job\JobInterface
*/
protected $job;
public function __construct(ValidableInterface $validator, JobInterface $job)
{
$this->validator = $validator;
$this->job = $job;
}
Run Code Online (Sandbox Code Playgroud)
这是我的验证器类的前几行:
namespace Project\Backend\Service\Form\Job;
use Project\Backend\Service\Validation\AbstractLaravelValidator;
class JobFormValidator extends AbstractLaravelValidator { …Run Code Online (Sandbox Code Playgroud)