Answer the question
In order to leave comments, you need to log in
Why is the correct connection not being used when requesting?
There are 2 databases:
db1 with the prices table and db2 with the diseases and model_price tables (link table)
The Price and Diseases models are polymorphically linked using the ModelPrice(MorphPivot) model
class Price extends Model
{
protected $connection = 'db1'
public function diseases(){
return $this->morphedByMany(Disease::class, 'modelable', 'model_price')->using(ModelPrice::class);
}
}
class Disease extends Model
{
protected $connection = 'db2'
public function prices(){
return $this->morphToMany(Price::class, 'modelable', 'model_price')->using(ModelPrice::class);
}
}
class ModelPrice extends MorphPivot
{
protected $connection = 'db2'
}
Price::find(1)->diseases
Disease::find(1)->prices
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question