6
0
Fork 0

省市区数据

release
李静 2021-12-07 10:42:29 +08:00
parent 8f54ffc9e4
commit 21a8732860
3 changed files with 113 additions and 0 deletions

View File

@ -0,0 +1,21 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Zone extends Model
{
public const TYPE_PROVINCE = 'province';
public const TYPE_CITY = 'city';
public const TYPE_AREA = 'area';
/**
* @var array
*/
protected $fillable = [
'name',
'parent_id',
'type',
];
}

View File

@ -0,0 +1,37 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
class CreateZonesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('zones', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('parent_id')->nullable()->comment('父级 ID');
$table->string('name')->comment('省/市/区 名称');
$table->enum('type', ['province', 'city', 'area'])->comment('类型');
$table->timestamps();
});
DB::unprepared(file_get_contents(base_path('database/sql/zones.sql')));
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('zones');
}
}

File diff suppressed because one or more lines are too long