nnjeim / world

A Laravel package which provides a list of the countries, states, cities, currencies, timezones and languages.
MIT License
737 stars 104 forks source link

Include specific field in response #45

Closed dpetrovaliev closed 1 year ago

dpetrovaliev commented 1 year ago

Hey, i have the following scenario: I should have a way to search cities by name and return the cities along with their country and state code: Here is my action:

$action = World::cities([
            'fields' => 'country,state',
            'search' => $request->get('query')
        ]);

As a result, I'm not receiving the state code but only the state id and state name. Is there any way to preload the states with the state_code?

nnjeim commented 1 year ago

@dpetrovaliev please look at the outcome here below Screenshot 2023-02-15 at 16 34 38 state code do not exist it is only state id and state name

dpetrovaliev commented 1 year ago

@nnjeim yes and the question was, how could I include it?

I think I found a solution:

added the state_code in the optional fields in world.php config file and then recreated all the tables and then included state_code in fields when searching cities.

nnjeim commented 1 year ago

@dpetrovaliev excellent, thank you for your input