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

This commit is contained in:
2025-04-01 12:00:05 +08:00
parent d560249789
commit d7e6ae75ec

View File

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