初始化项目
This commit is contained in:
46
app/Models/System/City.php
Normal file
46
app/Models/System/City.php
Normal file
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\System;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class City extends Model
|
||||
{
|
||||
protected $table = 'system_cities';
|
||||
|
||||
protected $fillable = [
|
||||
'parent_id',
|
||||
'name',
|
||||
'code',
|
||||
'pinyin',
|
||||
'pinyin_short',
|
||||
'level',
|
||||
'sort',
|
||||
'status',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'parent_id' => 'integer',
|
||||
'level' => 'integer',
|
||||
'sort' => 'integer',
|
||||
'status' => 'boolean',
|
||||
];
|
||||
|
||||
public function children(): HasMany
|
||||
{
|
||||
return $this->hasMany(City::class, 'parent_id')->orderBy('sort');
|
||||
}
|
||||
|
||||
public function activeChildren(): HasMany
|
||||
{
|
||||
return $this->hasMany(City::class, 'parent_id')
|
||||
->where('status', true)
|
||||
->orderBy('sort');
|
||||
}
|
||||
|
||||
public function parent()
|
||||
{
|
||||
return $this->belongsTo(City::class, 'parent_id');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user