2014-10-04 5 views
2

아래 오류로 strugging했습니다. 인터페이스 오류가 아니라 모델 오류입니다. 나는 아래 코드에서 무엇이 잘못되었는지 알지 못한다.BindingResolutionException 대상 [Illuminate Database Eloquent Model]이 인스턴스화 가능하지 않습니다.

이 문제를 해결할 생각이 없습니다.

회사 모델이 있습니다.

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(); 
    } 
} 

이 companyrepository입니다 companyrepositoryinterface

namespace ohbt\Repositories; 
interface CompanyRepositoryInterface{ 
} 

입니다 그리고 내 repositoryservices 공급자가 이미 응용 프로그램/설정/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(); 
} 

} 

정말 응용 프로그램에 추가

use Illuminate\Database\Eloquent\Model; 

class Company extends Eloquent{ 
    protected $softDelete = true; 
    protected $table = "companies"; 
    protected $fillable = []; 
    protected $guarded = []; 
} 

어떤 제안이나 도움을 피하십시오. 고맙습니다.

답변

0

사실, 이것이 모델 인스턴스화 문제에 대한 적절한 또는 좋은 해결책이라고 생각하지 않습니다. 그러나 그것은 나의 최근 문제를 해결했다.

RepossitoryServiceProvider의 특정 파일과 모델에 대해 설명했습니다. 그러나이 문제가있는 동안 다른 바인딩 작업은 말이되지 않습니다.

여기이 경우 내 솔루션

use \Company; //Company Model added 
use Illuminate\Database\Eloquent\Model; 
use Illuminate\Support\ServiceProvider; 
use ohbt\Repositories\Eloquents\CompanyRepository; //Company Repository added. 

class RepositoriesServiceProvider extends ServiceProvider { 

protected $defer = false; 

public function boot() 
{ 
    // 
} 

public function register() 
{ 
    $this->app->bind('ohbt\Repositories\BaseRepositoryInterface', 'ohbt\Repositories\Eloquents\AbstractRepository'); 

    $this->app->bind('VehicleRepositoryInterface', 'ohbt\Repositories\Eloquents\VehicleRepository'); 

    $this->app->bind('UserRepositoryInterface', 'ohbt\Repositories\Eloquents\UserRepository'); 

    $this->app->bind('GuestRepositoryInterface', 'ohbt\Repositories\Eloquents\GuestRepository'); 

    /** 
     * Comment out the previous binding function. 
     * $this->app->bind('CompanyRepositoryInterface', 
     * 'ohbt\Repositories\Eloquents\CompanyRepository'); 
     * directly return Repository Object rather than directory of Repository of Model 
     **/ 
    $this->app->bind('CompanyRepositoryInterface', function() 
    { 
     return new CompanyRepository(new Company); 
    }); 
} 

public function provides() 
{ 
    return array(); 
} 

} 

, 우리는 IOC의와 결합하는 모든 모델과 저장소 파일을 선언해야합니다. 그건 좋은 생각이 아니야. 감사합니다. 더 나은 접근을 위해 진보 된 솔루션이나 대답을 환영합니다.

+0

이제 companyrepository에서 사용하는 회사 검사기 서비스에 문제가 있습니다. ' $ this-> validator-> isValid ($ 속성); ' "비 객체의 속성을 가져 오려고 시도 중"오류가 있습니다. 적절한 해결책을 찾으십시오. 이 인터페이스를 다른 인터페이스와 바인딩 할 수없는 이유는 무엇입니까? –

+0

RepositoriesServiceProvider를 app.php의 providers 배열에 추가 했습니까? – billrichards