So I have the following models:
Organisation -> Location -> Smart -> Alarm
Right now I have an attribute on the Alarm model which does this:
public function getAlarmViewUrlAttribute() {
return "https://frontendui/organizations/" . $this->smart->location->organisation->id . "/controllers/" . $this->smart->id . "/alarms/" . $this->metadata['ref'];
}```
I have no issue with that. Until, this model is called via relationship from the Smart model to retrieve the alarms for that smart controller.
That is done like this:
```php
public function alarms(): HasMany {
return $this->hasMany(Alarm::class, 'mac_address', 'mac_address');
}
I then find that because of the alarm_view_url attribute, I end up with data that is absolute relationship hell:
smart
location
-> organisation
-> alarms ...
-> smart
-> location
-> organisation
Hopefully you get the picture, if there is 10 alarms, the json is just repeated over and over and over. There is children alarms too, and they call back to the Alarm model which they BelongTo, they are in the same boat. Hell. How do I work around this?