4 Commits

4 changed files with 42 additions and 12 deletions

View File

@@ -63,13 +63,18 @@ class Article
// 文章详情
public function read()
{
$article = ArticleModel::withoutField([
$article = ArticleModel::with(['category' => function($query) {
$query->field(['id', 'name' => 'category_name']);
}])
->withoutField([
'language_id',
'updated_at',
'deleted_at',
])
->bypk(request()->param('id'))
->find();
->find()
->bindAttr('category', ['category_name'])
->hidden(['category']);
if (is_null($article)) {
return error('文章不存在');
}

View File

@@ -61,14 +61,29 @@ class Attachment
{
$id = request()->param('id');
$attachment = AttachmentModel::withoutField([
'language_id',
'created_at',
'updated_at',
'deleted_at'
$attachment = AttachmentModel::with(['category' => function ($query) {
$query->field(['id', 'name' => 'category_name']);
}])
->field([
'id',
'category_id',
'name',
'desc',
'image',
'applicable_to',
'support_platform',
'attach',
'sort',
'recommend',
'status',
'seo_title',
'seo_keywords',
'seo_desc'
])
->bypk($id)
->find();
->find()
->bindAttr('category', ['category_name'])
->hidden(['category']);
if (empty($attachment)) {
return error('附件不存在');
}

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('产品不存在');
}

View File

@@ -61,13 +61,18 @@ class Video
*/
public function read()
{
$video = VideoModel::withoutField([
$video = VideoModel::with(['category' => function($query) {
$query->field(['id', 'name' => 'category_name']);
}])
->withoutField([
'created_at',
'updated_at',
'deleted_at'
])
->bypk(request()->param('id'))
->find();
->find()
->bindAttr('category', ['category_name'])
->hidden(['category']);
if (empty($video)) {
return error('视频不存在');
}