Oh yeah. I got it. I'll post the answer in case it's useful to someone. I tried to use merge()
earlier, but I should have used union()
.
In the models we do:
public function myRelation_1 {
return $this->myRelation()->where('level', 1);
}
public function myRelation_2 {
return $this->myRelation()->where('level', 2);
}
// Add
public function all_relation() {
return $this->myRelation_1()->union($this->myRelation_2());
}
// When calling in the controller, pass the following to the with() method
$res = Model::select('id','name', 'price')
->with('all_relation')
->where('status', '=', 1)
->first();
PS: Maybe it will be useful to someone. Thank you all for participating.