修复分类数据
This commit is contained in:
parent
9d5dda3522
commit
e522a263fe
|
|
@ -2,8 +2,10 @@
|
|||
|
||||
namespace Beike\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasOne;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
|
||||
class Category extends Model
|
||||
{
|
||||
|
|
@ -19,22 +21,22 @@ class Category extends Model
|
|||
'active' => 'boolean',
|
||||
];
|
||||
|
||||
public function children()
|
||||
public function children(): HasMany
|
||||
{
|
||||
return $this->hasMany(Category::class, 'parent_id');
|
||||
}
|
||||
|
||||
public function descriptions()
|
||||
public function descriptions(): HasMany
|
||||
{
|
||||
return $this->hasMany(CategoryDescription::class);
|
||||
}
|
||||
|
||||
public function description()
|
||||
public function description(): HasOne
|
||||
{
|
||||
return $this->hasOne(CategoryDescription::class)->where('locale', locale());
|
||||
}
|
||||
|
||||
public function paths()
|
||||
public function paths(): HasMany
|
||||
{
|
||||
return $this->hasMany(CategoryPath::class);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ class CategoryRepo
|
|||
->from('categories as c')
|
||||
->with(['description', 'children.description'])
|
||||
->where('parent_id', 0)
|
||||
->orderBy('position')
|
||||
->get();
|
||||
|
||||
$categoryList = CategoryList::collection($topCategories);
|
||||
|
|
|
|||
|
|
@ -23,6 +23,8 @@ class CategoryList extends JsonResource
|
|||
|
||||
if ($this->relationLoaded('children') && $this->children->count() > 0) {
|
||||
$item['children'] = self::collection($this->children);
|
||||
} else {
|
||||
$item['children'] = [];
|
||||
}
|
||||
return $item;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue