2017 © Pedro Peláez
 

library brcities

Full package with brazilian cities.

image

ruwer/brcities

Full package with brazilian cities.

  • Friday, September 30, 2016
  • by ricardoruwer
  • Repository
  • 0 Watchers
  • 12 Stars
  • 2,723 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 0 Open issues
  • 1 Versions
  • 6 % Grown

The README.md

BiRCities for Laravel 5

Codacy Badge Total Downloads Build Status, (*1)

  • A Laravel 5 package containing all Brazilian cities to your database.
  • Auto-fill the cities when you select the state. Built using Vanilla JS.
  • Works well with Cep Package.

Installation

Run in your terminal:, (*2)

composer require "ruwer/brcities":"dev-master"

Open the file config/app.php and add to "providers":, (*3)

'providers' => [
    // ...
    Ruwer\BRcities\BrcitiesServiceProvider::class,
],

Let's publish the package files into your project. Run in your terminal:, (*4)

php artisan vendor:publish

Now you have the following files in your project: - database/migrations/2014_10_12_000000_create_cities_table.php - database/seeds/CitiesTableSeeder.php, (*5)

You also have a copy of brcities.js in the following folders of your project: - public/js/brcities.js - resources/assets/js/brcities.js, (*6)

So, run in your terminal:, (*7)

composer dump-autoload
php artisan migrate
php artisan db:seed --class="CitiesTableSeeder"

Done! :), (*8)

Model

Now you can use your new model City, e.g.:, (*9)

use Ruwer\BRcities\City;

$states = City::select("state")->distinct("state")->orderBy("state")->get();
$pr_cities = City::where("state", "=", "PR")->orderBy("name")->get();

Routes

You also have the following routes returning JSON, e.g.: - myproject.dev/states - myproject.dev/cities/PR, (*10)

Usage

Create your form:, (*11)

<form id="form">
  <select name="state" class="js-state"></select>
  <select name="city" class="js-city"></select>
</form>

Include the .js file:, (*12)

<script src="{{ asset('js/brcities.js') }}"></script>

Call the script:, (*13)

<script>
  var cities = new Cities("#form");
</script>

Options

Define the class:, (*14)

//My Personal Options
var options = {
  stateInput: ".js-state", //default
  cityInput:  ".js-city", //default
  short: false //default (Long state names)
}

//Call the Script
var cities = new Cities("#form", options);

Set placeholders:, (*15)

<select name="state" class="js-state">
    <option value="">Please select...</option>
</select>
<select name="city" class="js-city">
    <option value="">Please select the state first...</option>
</select>

Default value:, (*16)

<select name="state" class="js-state" value="PR"></select>
<select name="city" class="js-city" value="3595"></select>

The Versions

30/09 2016

dev-master

9999999-dev

Full package with brazilian cities.

  Sources   Download

MIT

by Ricardo Ruwer

laravel brasil cidades estados