Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Laravel States Laravel Package

adrianmejias/laravel-states

View on GitHub
Deep Wiki
Context7

Laravel States

Laravel States is a bundle for Laravel, providing abbreviation, name and country code for US states.

Currently, I only have US states but additional states from other countries could be added using the country code column.

Please not that this is for Laravel 5 only.

Installation

Add adrianmejias/laravel-states to composer.json.

"adrianmejias/laravel-states": "~1.0"

Run composer update to pull down the latest version of Country List.

Edit app/config/app.php and add the provider and filter

'providers' => [
    AdrianMejias\States\StatesServiceProvider::class,
]

Now add the alias.

'aliases' => [
    'States' => AdrianMejias\States\StatesFacade::class,
]

Model

You can start by publishing the configuration. This is an optional step, it contains the table name and does not need to be altered. If the default name states suits you, leave it. Otherwise run the following command

$ php artisan vendor:publish

Next generate the migration file:

$ php artisan states:migration
$ composer dump-autoload

It will generate the <timestamp>_setup_states_table.php migration and the StatesSeeder.php seeder. To make sure the data is seeded insert the following code in the database/seeds/DatabaseSeeder.php

$this->call(StatesSeeder::class);

You may now run it with the artisan migrate command:

$ php artisan migrate --seed

After running this command the filled states table will be available.

Example

Example blade formatting:

@foreach(States::whereCountryCode('US')->get() as $state)
    {{ $state->name }} {{ $state->country_code }}<br>
@endforeach

Should result in:

Alabama US<br>
Arkansas US<br>
Arizona US<br>
...
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
ilhamsyabani/laravel-volt-starter
thethunderturner/filament-latex
ghostcompiler/laravel-querybuilder
webrek/laravel-telescope-mongodb
anousss007/blatui
zatona-eg/zatona-eg-api
cocosmos/filament-sticky-save-bar
patrickbussmann/oauth2-apple
3brs/enterprise-security-bundle
anousss007/vigilance
supportpal/eloquent-model
ardenexal/fhir-models
laravel-at/laravel-image-sanitize
romalytar/yammi-audit-log-laravel
ardenexal/fhir-validation
arshaviras/weather-widget
laravel-chronicle/core
sunchayn/nimbus
daikazu/eloquent-salesforce-objects
unseen-codes/chat