refactor: 修改产品详情接口添加分类名称字段输出
This commit is contained in:
@@ -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('产品不存在');
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user