I'm having an issue finding a way to make this work.
I have 3 tables.
Equipment, Locations, Rates
Each equipment has a rate as well as a possibility for a rate that has an additional discount_code from the location the equipment is.
I've set up two relationships for this, BaseRate and LocationRate. They are both simple relationships on the id=foreignkey. My goal was to filter the LocationRate using the equipment's location's discount_code in the eager loading query, like so:
Equipment::with(['location',
'baseRate',
'locationRate' => function($query) {
$query->where('discount_code', [????]);
}]);
The [????] bit is where I'm unsure how to access the location's discount property.
I understand that this may be a completely wrong way to do this kind of filtering.
Any help would be greatly appreciated.