【发布时间】:2014-11-29 02:22:12
【问题描述】:
我一直在努力解决以下错误。这不是接口错误,而是模型错误。我不知道下面的代码有什么问题。
Illuminate \ Container \ BindingResolutionException
Target [Illuminate\Database\Eloquent\Model] is not instantiable.
我没有任何想法来处理这个问题。
我有公司模型。
use Illuminate\Database\Eloquent\Model;
class Company extends Eloquent{
protected $softDelete = true;
protected $table = "companies";
protected $fillable = [];
protected $guarded = [];
}
即companyrepository接口
namespace ohbt\Repositories;
interface CompanyRepositoryInterface{
}
那是公司仓库
namespace ohbt\Repositories\Eloquents;
use Company;
use Illuminate\Database\Eloquent\Model;
use ohnt\Services\Validator\CompanyValidator as Validator;
use ohbt\Repositories\CompanyRepositoryInterface as CompanyRepositoryInterface;
class CompanyRepository extends AbstractRepository implements CompanyRepositoryInterface{
protected $company;
protected $validator;
public function __constructor(Model $company, Validator $validator){
$this->company = $company;
parent::__construct($this->company);
$this->validator = $validator;
}
public function create(array $attributes){
if($this->validator->isValid($attributes)){
$this->company->create($attributes);
return true;
}
return false;
}
public function getMessages(){
return $this->validator->getMessages();
}
}
并且我的存储库服务提供商已经添加到 app/config/app.php
namespace ohbt\Repositories;
use Illuminate\Support\ServiceProvider;
class RepositoriesServiceProvider extends ServiceProvider {
protected $defer = false;
public function boot()
{
//
}
public function register()
{
$this->app->bind('VehicleRepositoryInterface', 'ohbt\Repositories\Eloquents\VehicleRepository');
$this->app->bind('UserRepositoryInterface', 'ohbt\Repositories\Eloquents\UserRepository');
$this->app->bind('CompanyRepositoryInterface', 'ohbt\Repositories\Eloquents\CompanyRepository');
}
public function provides()
{
return array();
}
}
非常感谢任何建议和帮助。感谢先进。
【问题讨论】:
标签: laravel-4 dependency-injection model-binding