refactor: 修改文章列表
This commit is contained in:
@@ -21,7 +21,6 @@ class Article
|
||||
|
||||
$article = ArticleModel::withoutField([
|
||||
'language_id',
|
||||
'category_id',
|
||||
'author',
|
||||
'source',
|
||||
'desc',
|
||||
@@ -33,9 +32,10 @@ class Article
|
||||
'seo_keywords',
|
||||
'seo_desc'
|
||||
])
|
||||
->with('category')
|
||||
->where(function($query) use($param) {
|
||||
if (isset($param['category_id'])) {
|
||||
$query->category($param['category_id']);
|
||||
$query->where('category_id', '=', $param['category_id']);
|
||||
}
|
||||
})
|
||||
->withSearch(['title', 'created_at'], (function() use($param) {
|
||||
@@ -54,7 +54,12 @@ class Article
|
||||
->paginate([
|
||||
'page' => $param['page'],
|
||||
'list_rows' => $param['limit'],
|
||||
]);
|
||||
])
|
||||
->hidden([
|
||||
'category',
|
||||
'category_id'
|
||||
])
|
||||
->bindAttr('category', ['category_name' => 'name']);
|
||||
|
||||
return success('获取成功', $article);
|
||||
}
|
||||
|
||||
@@ -16,6 +16,12 @@ class ArticleModel extends ArticleBaseModel
|
||||
// 软删除标记数据字段
|
||||
protected $deleteTime = 'deleted_at';
|
||||
|
||||
// 关联分类
|
||||
public function category()
|
||||
{
|
||||
return $this->belongsTo(ArticleCategoryModel::class, 'category_id', 'id');
|
||||
}
|
||||
|
||||
// 搜索名称
|
||||
public function searchTitleAttr($query, $value, $data)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user