I have the following models:
Product
BaseProduct
BaseCode
Series
Each of them is something of a separate entity, but they\'re related.
I am somewhat new to 4.1, but it looks as though hasManyThrough()
was not designed for the types of relationships you are looking for and is really just a shortcut for two level deep eager loading.
Try traditional eager loading instead...
$data = Product::with('BaseProduct.BaseCode.Series');
You will need to make sure the relationships are setup in your models as necessary and instead of calling model names, you will want to call the methods that are defining the relationships.
Also obviously, be sure your models know what the primary keys are by using protected $primaryKey = 'SeriesID'
etc...
I created a HasManyThrough
relationship with unlimited levels: Repository on GitHub
After the installation, you can use it like this:
class Series extends Model {
use \Staudenmeir\EloquentHasManyDeep\HasRelationships;
public function products() {
return $this->hasManyDeep(Product::class,
[BaseCode::class, BaseProduct::class],
['SeriesId', 'BaseCodeId', 'BaseProductId']
);
}
}