Download the PHP package nerdsnipe/laravel-countries without Composer
On this page you can find all versions of the php package nerdsnipe/laravel-countries. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download nerdsnipe/laravel-countries
More information about nerdsnipe/laravel-countries
Files in nerdsnipe/laravel-countries
Package laravel-countries
Short Description Used to add country, state, city selectors to any laravel view. Provides all cities and states for 251 countries
License MIT
Homepage https://github.com/nerdsnipe/laravel-countries
Informations about the package laravel-countries
Laravel Countries Package
A Laravel package for working with countries, states, provinces, and cities. Use this package to easily add a dynamic country, state and cities select element series to your Laravel application. All required data is available in the included JSON files which are imported to your database.
Requirements
- PHP >= 8.1
- Laravel >= 9.0
Installation
You can install the package via composer:
You publish the package config file.
This will publish the file.
Set the and to reflect where to place script and css elements within your view or layout.
Publish the package's data (json) files.
This will copy the countries.json, states.json, and cities.json files to your storage/app/laravel-countries directory.
Example usage
The component relies on providing the id and name of the select element and has the optional values for country, state and city.
This example sets the name attribute of the component to "location", and passes in the IDs of the selected country, state, and city as props, which will pre-select those options when the component is rendered.
The component will then dynamically update the state and city options based on the selected country and state.
Optionally (very useful for the end-user) you can use select2 and set the styles using the set either (or both) of them to true to enable the search feature and select2 styling.
Note: Based on the setting (above) access the submitted values as:
Use the Facade to get access to the underlying data, remember these are large data-sets
Will return collections as JSON. If you want to use the data you can extract it from the collection
After using the country, state and city dynamic selector the data will also be available in the cache.
TODO
- Add function to enable a default country, city and state
- Add ability to focus countries by as an option
- Add the use of in place of name to return country names in their native language
- Add a gate/middleware to the routes. Because the country select series are likely to be used on registration pages, there is currently no middleware attached to the routes. This exposes the country, state and city json results without any sort of can:view authorization
- Add a method to cache all states and cities through the Facade ()
Credits
A special thanks and shout-out to the team at Spatie we appreciate all you do for the Laravel open-source community. You have inspired us to extract useful functionality we have created for internal and client applications and make them available as an open source package. This is the first such package.
License
The Laravel Countries Package is open-sourced software licensed under the MIT license.
Change Log
V1.1
- Added , , to the Facade
- Added ability to hide the labels
- Added ability to stretch (full-width) the select input
Data available in Countries
Data Available in States
Data available in Cities
All versions of laravel-countries with dependencies
laravel/framework Version ^9.19|^10.0
spatie/laravel-package-tools Version ^1.14.0