refactor: 修改产品详情接口添加分类名称字段输出

This commit is contained in:
2025-04-01 12:00:05 +08:00
parent 7b82db2366
commit 53da5b8a99

View File

@@ -71,14 +71,19 @@ class Product
// 产品详情 // 产品详情
public function read() public function read()
{ {
$product = ProductModel::withoutField([ $product = ProductModel::with(['category' => function($query) {
$query->field(['id', 'name' => 'category_name']);
}])
->withoutField([
'language_id', 'language_id',
'created_at', 'created_at',
'updated_at', 'updated_at',
'deleted_at' 'deleted_at'
]) ])
->bypk(request()->param('id')) ->bypk(request()->param('id'))
->find(); ->find()
->bindAttr('category', ['category_name'])
->hidden(['category']);
if (empty($product)) { if (empty($product)) {
return error('产品不存在'); return error('产品不存在');
} }