Package Data | |
---|---|
Maintainer Username: | ricardoruwer |
Maintainer Contact: | ricardoruwer@gmail.com (Ricardo Ruwer) |
Package Create Date: | 2016-05-04 |
Package Last Update: | 2018-11-29 |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-12-14 15:00:45 |
Package Statistics | |
---|---|
Total Downloads: | 4,862 |
Monthly Downloads: | 0 |
Daily Downloads: | 0 |
Total Stars: | 12 |
Total Watchers: | 1 |
Total Forks: | 3 |
Total Open Issues: | 0 |
Run in your terminal:
composer require "ruwer/brcities":"dev-master"
Open the file config/app.php and add to "providers":
'providers' => [
// ...
Ruwer\BRcities\BrcitiesServiceProvider::class,
],
Let's publish the package files into your project. Run in your terminal:
php artisan vendor:publish
Now you have the following files in your project:
You also have a copy of brcities.js in the following folders of your project:
So, run in your terminal:
composer dump-autoload
php artisan migrate
php artisan db:seed --class="CitiesTableSeeder"
Done! :)
Now you can use your new model City, e.g.:
use Ruwer\BRcities\City;
$states = City::select("state")->distinct("state")->orderBy("state")->get();
$pr_cities = City::where("state", "=", "PR")->orderBy("name")->get();
You also have the following routes returning JSON, e.g.:
Create your form:
<form id="form">
<select name="state" class="js-state"></select>
<select name="city" class="js-city"></select>
</form>
Include the .js file:
<script src="{{ asset('js/brcities.js') }}"></script>
Call the script:
<script>
var cities = new Cities("#form");
</script>
Define the class:
//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:
<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:
<select name="state" class="js-state" value="PR"></select>
<select name="city" class="js-city" value="3595"></select>