Tôi có một hùng biện Mẫu gọi là bề mặt mà phụ thuộc vào một đối tượng ZipCodeRepository:dependency injection Laravel5 trên Model
class Surface extends Model{
public function __construct(ZipCodeRepositoryInterface $zipCode){...}
và một đối tượng Địa chỉ rằng bề mặt hasMany.
class Address extends Model{
public surfaces() { return $this->hasMany('App/Surface'); }
}
Vấn đề của tôi là khi tôi gọi $address->surfaces
tôi nhận được lỗi sau:
Argument 1 passed to App\Surface::__construct() must be an instance of App\Repositories\ZipCodeRepositoryInterface, none given
Tôi nghĩ IoC sẽ tự động tiêm đó.
Xem tại đây: https://stackoverflow.com/questions/22338161/cant-pass-class-instance-to-constructor/22338753 ... đặc biệt là sự cố được mở tại github – svrnm