Getting $row information in the subfield of relationship. #703
-
Hello to everyone! Here is my situation. I have HasMany type of relationship. Basically store has many zones. So in the crud page of the store I use relationship field which handles zones. Zone in its turn has many locations. Location is a shelf in the store. And I need to show the user how many locations in each zone of the store. So in the relationship field for the zone I use 3 subfields: name, code, locations_qty. Name and code is easy as these are just text fields populated from db. And the last one locations_qty is a tricky one. I have created for it custom field and try to use it as a subfield. But to identify correct number of locations for the given zone I need to know the id of the zone. And I don't know how to get this information inside my custom subfield. I researched a little bit backpack's source code and identified that this information exists in $row variable in repeatable_row.blade.php. But all my attempts to access it failed and I keep getting exception "Undefined variable $row" . However if I make dd I can see this variable and its contents. But as soon as I try to access it throws before mentioned exception. Can anyone help with this? Basically I need to get the id of the current row relation in my custom subfield inside relationship field. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Hi @Uteev, so each store has many zones, each zone has many locations, is that right? Shouldn't this value be computed based on the number of actual locations on the database? |
Beta Was this translation helpful? Give feedback.
Hi @pxpm , thanks for the suggestion!
Currently I just created the new custom field that shows all zones in rows and since it is my custom field I don't have the problem to have row information. Of course I had to do a bit of programming including javascript to replicate the behavior of backpack's relationship field but at the end I achieved what I needed. And by the way I totally removed locations_qty field from db as I compute this information dynamically.
Although I was able to achieve what I need still I think it would be a good use for many developers to have access to $row inside subfield.