There's two ways to go about it:
- You can use the staudenmeir/belongs-to-through package.
- You can define
hasOneThroughin reverse order.
For 2) you would need to define the relationship as follows:
// Payments
public function property(): HasOneThrough
{
return $this->hasOneThrough(
Property::class,
Booking::class,
'id',
'id',
'booking_id',
'property_id',
);
}
works the same for HasManyThrough as well.
Also, you can clean up the query:
return $query->whereRelation('property', 'id', $value);