belongsTo(StockPosition::class, 'position_id', 'position_id'); } // If you have a StockEntry model, you can set up a many-to-many via the pivot: public function entries() { return $this->belongsToMany( StockEntry::class, // your entry model 'stock_entries2section', // pivot table 'section_id', // this modelʼs FK on pivot 'entry_id' // other modelʼs FK on pivot ) ->withPivot('count') ->withTimestamps(); } public function occupied(): bool { return $this->entries()->exists(); } public function getStorageAddressAttribute(): string { // calls your existing method, which will // loadMissing the relations if needed return $this->storageAddress(); } public function storageAddress(): string { // eager-load the whole hierarchy if not already $this->loadMissing('position.shelf.rack.line.room'); $position = $this->position; $shelf = $position->shelf; $rack = $shelf->rack; $line = $rack->line; $room = $line->room; return sprintf( '%s-%s-%s-%s-%s-%s', $room->room_symbol, $line->line_symbol, $rack->rack_symbol, $shelf->shelf_symbol, $position->position_symbol, $this->section_symbol ); } }