PHP code example of znck / cities
1. Go to this page and download the library: Download znck/cities 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/ */
znck / cities example snippets
return [
// ...
'providers' => [
// ....
Znck\Cities\CitiesServiceProvider::class,
]
// ...
];
namespace App;
use Illuminate\Database\Eloquent\Model;
use Znck\Cities\City as CityTrait;
class City extends Model {
use CityTrait;
}
Schema::create('countries', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('code', 2)->unique();
$table->timestamps();
});
Schema::create('states', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('code', 5)->unique();
$table->unsignedInteger('country_id');
$table->timestamps();
$table->foreign('country_id')->references('id')->on('countries');
});
Schema::create('cities', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('code', 10)->unique();
$table->unsignedInteger('state_id');
$table->timestamps();
$table->foreign('state_id')->references('id')->on('states');
});
php artisan vendor:publish --provider='Znck\Cities\CitiesServiceProvider'