urameshibr/brazilcities

包含巴西城市的包

1.2 2020-08-24 15:47 UTC

This package is auto-updated.

Last update: 2024-09-25 01:02:30 UTC


README

artesaos/cidadesbr 存储库的包替代品

在您的Laravel项目数据库中添加巴西城市表

Latest Stable Version Total Downloads Maintainer License

如何使用

为Laravel 7添加包

composer require urameshibr/brazilcities

对于Laravel 5版本,使用1.1.0版本

composer require urameshibr/brazilcities:"1.1.0"

config/app.php文件中添加Provider

// file START ommited
'providers' => [
    // other providers ommited
    Urameshibr\Providers\CityServiceProvider::class,
],
// file END ommited

导入migrations/seeds

$ php artisan vendor:publish --provider="Urameshibr\Providers\CityServiceProvider"

执行

$ composer dump-auto
$ php artisan migrate
$ php artisan db:seed --class="CitySeeder"

模型Urameshibr\City

Urameshibr\City模型已可供使用

<?php

namespace Urameshibr;

use Illuminate\Database\Eloquent\Model;

class City extends Model{

    public $timestamps = false;

    protected $fillable = ['name', 'uf'];
}

路由

以下路由已可供使用

Route::get('/ufs/', function($uf = null){
    return response()->json(\Urameshibr\City::select('uf')->distinct('uf')->orderBy('uf')->get());
});

Route::get('/cities/{uf}', function($uf = null){
    return response()->json(\Urameshibr\City::where('uf', $uf)->orderBy('name')->get());
});

jQuery助手

如果您需要,有一个插件可供通过ajax加载selectBoxes。

添加scripts.js

<script src="/vendor/urameshibr/cities/js/scripts.js"></script>

HTML

<select id="uf" default="MG"></select>
<select id="city"></select>

JS

$('#uf').ufs({
    onChange: function(uf){
        $('#city').cities({uf: uf});
    }
});