Answer the question
In order to leave comments, you need to log in
I can't make a correct query to get data through an intermediate table?
ORDERS:
id
status_id
.....
ORDER_ITEMS:
id
order_id
.....
SCHEDULE_SLOTS
id
order_item_id
......
// Отношение «один-к-одному» без проблем
public function getOrderItem() {
return $this->hasOne('ModelOrderItem', 'id', 'order_item_id');
}
// А вот тут начинаются трудности
public function getOrder() {
return $this->hasOneThrough('ModelOrder', 'ModelOrderItem', ..... );
}
public function getOrderItem() {
return $this->hasOne('ModelOrderItem', 'id', 'order_item_id')->with(['getOrder']);
}
$returnData = ModelScheduleSlots::with(['getOrderItem', 'getOrder'])
->whereHas('getOrder', function ($q) {
$q->where('status_id', 1);
});
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