Laravel-Backpack / addons

A place for the Backpack community to talk about possible Backpack add-ons.
5 stars 2 forks source link

Country > State > City field #24

Open tabacitu opened 3 years ago

tabacitu commented 3 years ago

This SO question made me realise it's not that easy to create this inside Backpack. I mean sure we have a way, but it's not dead-simple, where you just make one call that adds these 3 fields, with the entire database of Countries, States and Cities to it. And... it could be... 😂

https://stackoverflow.com/questions/64477629/how-to-the-dependent-dropdown-in-laravel-backpack-of-country-state-and-city

Don't know how many people would be interested in this though. Do people still use this way of adding location information, or does everybody use the address_google or address_algolia -like fields?

Food for thought.

promatik commented 3 years ago

I think if you don't need to much precision, google or algolia are ok.

Once I had to create a system to support the Portuguese administrative regions, District > County > Parish (I believe many countries use a similar model). And I needed that clear division between administrative regions, to then query my models over that.

It was painful back then 😬 nowadays, this would have been much easier, if I used fetch operations, and the new relationship field with the dependencies attribute.

In my case, Country > State > City field wouldn't have been enough, if we are going to create a plugin for this we may take into account that many country administrative regions are different.


What I think it would be a possible option, and very likely to fit everyone's needs, is to create some king of relationship_dependency. Where the developer could setup his own Models.

[
    'type' => "relationship_dependency",
    'name' => 'address',
    'entities' => [
        App\Models\Country::class,
        App\Models\State::class => 'country', // 'country' is the method defining the relationship to the previous model
        App\Models\City::class => 'state', // 'state' is the method defining the relationship to the previous model
    ],
]

And this would create 3 selects depending on each other.

Again, I think this is not that hard to achieve with the current relationship field using the dependencies attribute.

tabacitu commented 3 years ago

Yeah... relationship_dependency sounds like a good name for it. Hopefully it doesn't go the way of checklist_dependency 😂