World Countries

The countries component provides you with an interface to manage your countries.

As a bonus, 257 countries are already seeded for you when installing the platform.

In order to provide you with a complex crud functionality inside the admin, the countries crud implements the following out of the box:

Admin Interface

Before going deeper, you should know that there's already a section in the admin from where you can manage all your countries, states and cities.

You can find the countries section inside Admin -> Geo Location -> Countries.
Feel free to explore all available options this section offers.

Countries List

Seeder Class

The countries component provides a seeder class for seeding all available countries into your countries database table. The seeder only works with an empty countries database table.

If you've successfully installed the Varbox platform, you should find the CountriesSeeder.php file inside your database/seeds directory and the countries.sql file inside your database/sql directory.

You can seed your countries, if you haven't done so yet, by using the following artisan command:

php artisan db:seed --class="CountriesSeeder"

Usage

Let's see the most common things you can do using countries.

Fetch Country States

You can get a country's states by using the states has many relation present on the Varbox\Models\Country model.

use Varbox\Models\Country;

$country = Country::find($id);
$states = $country->states;

Fetch Country Cities

You can get a country's cities by using the cities has many relation present on the Varbox\Models\Country model.

use Varbox\Models\Country;

$country = Country::find($id);
$cities = $country->cities;

Sort Countries Alphabetically

You can fetch countries in alphabetical order by using the alphabetically query scope present on the Varbox\Models\Country model.

use Varbox\Models\Country;

$countries = Country::alphabetically()->get();

Overwrite Bindings

In your projects, you may stumble upon the need to modify the behavior of these classes, in order to fit your needs. Varbox makes this possible via the config/varbox/bindings.php configuration file. In that file, you'll find every customizable class the platform uses.

For more information on how the class binding works, please refer to the Custom Bindings documentation section.

The country classes available for binding overwrites are:

Varbox\Models\Country

Found in config/varbox/bindings.php at models.country_model key.
This class represents the country model.

Varbox\Controllers\CountriesController

Found in config/varbox/bindings.php at controllers.countries_controller key.
This class is used for interactions with the "Admin -> Geo Location -> Countries".

Varbox\Requests\CountryRequest

Found in config/varbox/bindings.php at form_requests.country_form_request key.
This class is used for validating any country when updating.

Varbox\Filters\CountryFilter

Found in config/varbox/bindings.php at filters.country_filter key.
This class is used for applying the filtering logic.

Varbox\Sorts\CountrySort

Found in config/varbox/bindings.php at sorts.country_sort key.
This class is used for applying the sorting logic.