PHP code example of lucenarenato / laravel-cidadesbr

1. Go to this page and download the library: Download lucenarenato/laravel-cidadesbr 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/ */

    

lucenarenato / laravel-cidadesbr example snippets


// file START ommited
'providers' => [
    // other providers ommited
    'Lucenarenato\Providers\CidadesServiceProvider',
],
// file END ommited



namespace Lucenarenato;

use Illuminate\Database\Eloquent\Model;

class Cidade extends Model{

    public $timestamps = false;

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

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

Route::get('/cidades/{uf}', function($uf = null){
    return response()->json(\Lucenarenato\Cidade::where('uf', $uf)->orderBy('nome')->get());
});
sh
$ composer dump-auto
$ php artisan migrate
$ php artisan db:seed --class="CidadesSeeder"