PHP code example of brew / brazil-locations

1. Go to this page and download the library: Download brew/brazil-locations library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

brew / brazil-locations example snippets


use App\Models\State;

$states = State::orderBy('name')->get();

$state  = State::where('uf', 'SP')->first();
$cities = $state->cities;

use App\Models\City;

$city  = City::where('ibge_code', '3509502')->first();
$state = $city->state; // São Paulo

$states = State::with('cities')->get();

use App\Models\City;
use App\Models\State;
use Filament\Forms\Components\Select;
use Filament\Forms\Get;

Select::make('state_id')
    ->label('State')
    ->options(State::orderBy('name')->pluck('name', 'id'))
    ->live()
    ->

use App\Models\State;

$states = State::orderBy('name')->get();

$state  = State::where('uf', 'SP')->first();
$cities = $state->cities;

use App\Models\City;

$city  = City::where('ibge_code', '3509502')->first();
$state = $city->state; // São Paulo

$states = State::with('cities')->get();

use App\Models\City;
use App\Models\State;
use Filament\Forms\Components\Select;
use Filament\Forms\Get;

Select::make('state_id')
    ->label('Estado')
    ->options(State::orderBy('name')->pluck('name', 'id'))
    ->live()
    ->
bash
php artisan brazil-locations:install
bash
php artisan vendor:publish --tag=brazil-locations-migrations
php artisan vendor:publish --tag=brazil-locations-models
php artisan vendor:publish --tag=brazil-locations-seeders

php artisan migrate
php artisan db:seed --class=StateSeeder
php artisan db:seed --class=CitySeeder
bash
php artisan brazil-locations:install
bash
php artisan vendor:publish --tag=brazil-locations-migrations
php artisan vendor:publish --tag=brazil-locations-models
php artisan vendor:publish --tag=brazil-locations-seeders

php artisan migrate
php artisan db:seed --class=StateSeeder
php artisan db:seed --class=CitySeeder